Word: 아직 저장되지 않은 문서 위치 필드 업데이트

Word: 아직 저장되지 않은 문서 위치 필드 업데이트

onSave따라서 VBA에는 또는 이벤트 가 없기 때문에 afterSave문서를 저장하고 문서 위치를 업데이트하는 방법을 찾는 데 문제가 있습니다(저장된 후).

따라서 이 문서가 사용되는 가장 일반적인 방법은 다음과 같습니다.

  1. 템플릿에서 새 문서 만들기
  2. 문서 편집
  3. 문서를 다른 이름으로 저장(네트워크의 일부 위치)

내 상사는 모든 문서로 인해 혼란스러워서 다시 찾는 데 어려움을 겪고 있습니다.
그래서 그는 이 문서가 어디에 저장되어 있는지 알고 싶어합니다.
바닥글에 문서 위치 필드를 추가하고 VBA 프로젝트에 이 코드를 추가했습니다.

Sub AutoOpen()
'
' AutoOpen Macro
'
'
   Dim aStory As Range
   Dim aField As Field

   For Each aStory In ActiveDocument.StoryRanges

      For Each aField In aStory.Fields
         aField.Update
      Next aField

   Next aStory

 ' set document as unchanged (prevents save dialog popping up when closing)
 ' further edits will set this back to false and restore
 ' the save dialog on close
 ActiveDocument.Saved = True
End Sub

Private Sub wdApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)

    ActiveWindow.ActivePane.View.Type = wdPrintView
    Application.ScreenUpdating = True
    Selection.WholeStory
    ActiveDocument.Fields.Update
    ActiveDocument.Save

End Sub

모든 것은 activeDocument.Save 지점까지 작동하며 적어도 한 번은 저장되어야 합니다.
beforeSave 이벤트가 올바르게 저장되기 전이고 위치 경로가 없다고 가정하기 때문에 다소 모호한 부분도 있습니다. 이 일을 올바르게 하려면 어떻게 해야 합니까?

답변1

이 필드는 인쇄 미리보기로 업데이트됩니다. 그래서 제가 사용하는 비결은 AutoOpen 매크로에서 인쇄 미리보기를 만드는 것입니다.

Sub AutoOpen()
    Application.Run MacroName:="MathTypeCommands.UIWrappers.FilePrintPreview"
    ActiveDocument.ClosePrintPreview
End Sub

관련 정보