Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
      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

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?

share|improve this question
"My boss is confused by all of his documents" - Isn't that just typical. :) – Karan Feb 27 '13 at 6:38

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"
End Sub
share|improve this answer

You must log in to answer this question.

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