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:
- create new document from template
- edit document
- 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?