Word 문서에서 일부 정보를 가져 오기 위해 Excel에서 실행되는 VBA 매크로가 있습니다. 구문 분석을 시작하기 전에 목차 및 기타 필드를 제거하고 싶습니다. 아래 코드는 Office 2010에서 작동하지만 Office 2013에서는 작동하지 않습니다. "개체 필드에서 메서드 삭제가 실패했습니다" 오류 메시지가 표시되지만 이유를 이해할 수 없습니다.Word 필드 삭제 Word 2010에서 작동하는 Word 2013에서 VBA가 작동하지 않습니다.
팁 주셔서 감사합니다! 대신 인덱스를 삭제 시도에
보
Sub ImportBOD()
Dim wdFileName As Variant
Dim WordApp As Object
Dim wdDoc As Word.Document
Dim fld As Word.Field
wdFileName = Application.GetOpenFilename("Word files (*.docx),*.docx", ,"Choose the Word document")
If wdFileName = False Then Exit Sub '(user cancelled import file browser)
Set WordApp = CreateObject("Word.Application")
Set wdDoc = WordApp.Documents.Open(wdFileName, ReadOnly:=True)
'Get rid of table of contents and other fields
For Each fld In wdDoc.ActiveWindow.Document.Fields
fld.Delete
Next
wdDoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub
지난 루핑 코멘트를 기준으로합니다. 아래에서 답변 + 내 의견을 참조하십시오. –