2017-09-11 6 views
0

Word 문서 폴더에 몇 가지 사용자 지정 문서 속성을 추가하려고합니다.이 루프가 CustomDocumentProperties 작업을 추가하지 않는 이유는 무엇입니까?

루프 자체가 잘 작동한다는 것을 알고 있습니다. 다른 코드를 사용하여 동일한 루프를 사용하여 기존 사용자 지정 문서 속성을 수정 한 다음 업데이트했기 때문입니다.

사용자 지정 문서 속성을 추가하는 코드도 작동합니다. 단일 문서의 매크로를 사용하여 정상적으로 작동하는지 테스트했습니다.

루프가 작동하고 루프 내의 코드가 작동하기 때문에 문제가 무엇인지 파악할 수 없습니다.

Sub add_custom_docproperties() 

Dim file 
Dim path As String 

Dim filepath As Variant 
filepath = InputBox("Please enter the filepath for the files you want to 
update.", "Input Filepath", "Copy filepath here...") 
Select Case StrPtr(response) 
Case 0 
endednotification = MsgBox("The macro has been ended.", , "Notification") 
Exit Sub 
Case Else 
End Select 

path = filepath & "\" 

file = Dir(path & "*.*") 

'Application.ScreenUpdating = False 

Do While file <> "" 

    Documents.Open FileName:=path & file 

     Check = MsgBox(path & file, , "Check") 

     ActiveDocument.CustomDocumentProperties.Add Name:="firstdocprop", 
      _LinkToContent:=False, Type:=msoPropertyTypeString, Value:="The First One" 
     ActiveDocument.CustomDocumentProperties.Add Name:="seconddocprop", 
      _LinkToContent:=False, Type:=msoPropertyTypeString, Value:="Second" 
     ActiveDocument.CustomDocumentProperties.Add Name:="thirddocprop", 
      _LinkToContent:=False, Type:=msoPropertyTypeString, Value:="Third" 

'original example from: 
'https://msdn.microsoft.com/en-us/vba/office-shared-vba 
/articles/documentproperties-add-method-office 

    ActiveDocument.Save 
    ActiveDocument.Close 

    'set file to next in Dir 
    file = Dir() 

Loop 

'Application.ScreenUpdating = True 

MsgBox "The macro is complete." 

End Sub 

당신은 내가 내가 수정 MSDN에서 시도한 첫 번째 예제와이 주석을 볼 수 있듯이 :

여기에 코드입니다.

내가 도움이되지 않았다는 것을 설명하는 리소스를 알려주지 만 사전 도움을 주셔서 감사합니다.

답변

0

Save 명령을 실행할 때 실제로 변경 내용을 저장하는 것이 Word에서 을 무시하기로 결정한 경우에만 변경됩니다. 당신은이가 마지막으로 시작된 이후 문서가 저장되지 않았 음을 말씀을 말씀으로 저장 강제 할 수

변경 :

ActiveDocument.Saved = False 
ActiveDocument.Save 
ActiveDocument.Close 
+0

너무 감사합니다! 나는 그것이 단순 할 것이라고 생각했다. 그것은 나를 미치게했다. – Jlanger