0

So since VBA doesn't has a onSave or afterSave event i have troubles finding a way to save my document AND updateing the Document-Location (after it has been saved).

So the most common way this document will be used is:

  1. create new document from template
  2. edit document
  3. save document as (some location in the network)

My boss is confused by all of his documents and is having trouble finding them again.
So he wants to see where are this documents saved.
I added the document location field in the footer and added this code in the VBA project.

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

Everything works till the activeDocument.Save point, and it has to been saved before at least one time.
What is kinda obviuos too because i assume the beforeSave event is before it is saved propertly and so there is no location-path... What can i do to get this thing right?

1
  • 1
    "My boss is confused by all of his documents" - Isn't that just typical. :)
    – Karan
    Feb 27, 2013 at 6:38

1 Answer 1

1

This field will be updated by a print preview. So the trick I use is creating a print preview in the AutoOpen macro.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .