Add File Name and Path

Home Up Odds & Ends Photo Gallery Search Contact Me

 

 

The information in this website is provided without risk or obligation and free of charge.  However, if you have benefitted from my efforts here and would like to make a contribution to help me continue and maintain this work then any donation will be greatly appreciated. Please click the adjacent button to access PayPal.  Thank you.
 

1.  Open a new blank document.  The title bar will display:

 

2.  Let's save this document as Exercise One.  Click File>Save and the File Save As dialog box will open to the directory path you have chosen in Tools>Options>File Locations>Documents.  Note:  My settings are D:\My Documents\Word Documents.  Yours are likely different.

3.  The title bar now displays the file name Exercise One.

4. With a few simple macros you can customize your Word installation to display the full document path in the title bar.  The first is an AutoOpen macro that runs each time a document is opened.  The AutoOpen macro can be stored in a macro project in your Normal.dot template.

          Sub AutoOpen()

          ActiveWindow.Caption = ActiveDocument.FullName

          End Sub

 

Help is on the way applying macros at: Graham Mayor's "Idiots' guide to installing macros from newsgroup listings"

5. With the macro installed and the document reopened, the title bar displays the document full name and path.

6. There's a hiccup.  Click File>Save As again, and save the file with a new name.  Let's call it Exercise Two.  As you see in the graphic below, Word has taken its ball and gone home. We have lost the path.   

7. OK, Close Exercise Two and open it again.  The recently installed AutoOpen macro will have Word back in the game.  Ninety-nine out of a hundred people can probably live with this inconvenience.  If however, you are a perfectionist there is a way to make Word play the first time.  Here is another macro that stands in for the the built-in Word SaveAs command.  You install the macro in the same manner as the AutoOpen macro described above:

         Sub FileSaveAs()
 

         If Dialogs(wdDialogFileSaveAs).Show = 0 Then Exit Sub
         System.Cursor = wdCursorNormal
         ActiveWindow.Caption = ActiveDocument.FullName

 

         End Sub

 

8. After you have installed the macro, use File>Save As and save Exercise Two as Exercise Three.  Bingo!!  The title bar displays: 

 

9. Do you want the file name or file name and path displayed in your document and printed?  Word's built-in AutoText entries makes this a simple process.  Most people want the file information to show in the header or footer on each page.  For this reason the AutoText entries are stored in the Header and Footer category.  Select View>Header and Footer and place your cursor in the header where you want the information displayed. Then click Insert AutoText>Filename and Path.

10. Close the Header and Footer toolbar.  The document header now displays:

11. Another hiccup.  Use File>Save As and save Exercise Three as Exercise Four.  Word is having another tantrum.  The title bar looks fine, but the document information is incorrect (see graphic below).  The document information is constructed using  a Word field (my documents display field shading.  Yours can to with Tools>Options>Show>Field Shading>Always).  In most cases Word fields are not updated automatically. Unless you have changed the default settings in File>Print>Options>Printing Options, Word fields will update at time of printing.  Go ahead and try it.  Click View>Print Preview and then close the Preview screen.    

12. Perfectionist don't fear.  If you can't live with that minor inconvenience then more macro code will come to your rescue.  All we need to do is modify the SaveAs macro to include instructions for updating fields.

Sub FileSaveAs()
Dim pRange As Word.Range
Dim oFld As Field
On Error GoTo Handler
Retry:
With Dialogs(wdDialogFileSaveAs)
    If .Show = 0 Then Exit Sub
End With
System.Cursor = wdCursorNormal
ActiveWindow.Caption = ActiveDocument.FullName
For Each pRange In ActiveDocument.StoryRanges
    Do
        For Each oFld In pRange.Fields
            If oFld.Type = wdFieldFileName Then
                oFld.Update
            End If
        Next oFld
        Set pRange = pRange.NextStoryRange
    Loop Until pRange Is Nothing
Next
ActiveDocument.Save
Exit Sub
Handler:
If Err.Number = 5155 Or Err.Number = 5153 Then
MsgBox Err.Decription, vbOKOnly
Resume Retry
End If
End Sub

13. All set?  Let's save our document once again as Exercise Five.


Looking for something else?

Google