Full Path Names in Word

Written by Allen Wyatt (last updated January 30, 2021)
This tip applies to Word 97, 2000, 2002, and 2003


1

When you open a document in Word, the file name for the document is displayed in the title bar. At times, it would be nice to display more than a simple file name in the title bar. Many readers could profit by a way to display a full path name along with the file name in the title bar. Unfortunately, Word does not provide a way to do this easily. (After all, how difficult would it be to include a check box for this option?)

There are a couple of ways that this can be approached. If you only need to know the full path name once in a while, then you can create a very simple macro and assign it to a toolbar button. When you click on the button, the information in the title bar for the active window is changed to reflect the full path name. This macro, called ChangeCaption, is as follows:

Sub ChangeCaption()
    ActiveWindow.Caption = ActiveDocument.FullName
End Sub

Again, this macro is great for occasional use. If you desire, you can also rename this macro as AutoOpen, and then all documents, when opened, will display the full path name. There are a couple of big drawbacks to this option, however. Whenever you rename the document by using Save As to save it under a different name, the new file name (and path) are not updated in the title bar unless you rerun the macro. Secondly, if you have virus checking turned on, then it may interpret your macro (assigned to AutoOpen) as an attempt by a macro virus to mess with your system.

There is a way to create a more comprehensive and automatic approach. In order to customize Word to include the full path name, it is necessary to understand the type of interface used by Word. Word is a multiple document interface (MDI) application. This means the main application window (for Word) is the parent application window and this window can contain document windows (child windows) for each open document. When a document window is maximized, Word's title bar displays a combination of the application title (Microsoft Word) and the name of the document file. If documents are displayed in a partial screen or minimized state, then the parent window displays just the application name (Microsoft Word) and each child window shows the title of the document contained in that window. Thus, all that needs to be changed is the child window title bar to include the path with the file name.

The comprehensive approach relies on the use of Word application events. Essentially, the steps used in accomplishing this approach are as follows:

  1. Set up Word to trigger application events (they're built in to Word, but they don't happen automatically).
  2. Write some the actual title-bar changing code for the DocumentChange event.

The DocumentChange event, once set-up, happens almost every time the user activates a child (document) window. You'll notice I said "almost." This is because the event doesn't get triggered if the child window is a duplicate window to an open document (for instance, the window one gets when choosing New Window from the Window menu). This is effectively two views of the same document so there is no document change when switching from one view to the other. Consequently, if a document is open and the user opens a new window to the same document, it won't automatically have it's title bar changed by the code run from the DocumentChange event. It will be changed later if and when the user changes to this 'new window' view from some other child window containing a different document, however.

The second issue is that the DocumentChange event also doesn't get triggered when a new document is saved. So, if a unsaved document (such as Document1, Document2, etc.) is saved, the title bar doesn't change until the focus is taken away from the newly saved file and then given back. Fortunately, this can be worked around.

The first step, then, is to activate the Word application events. You can do this by following these steps. (The examples here are not included on the WordTips CD-ROM. They can, however, be easily created by following the steps outlined.)

  1. Start Word, and then close all open documents.
  2. Press ALT+F11 to start the Visual Basic Editor. The title bar for the Editor should say "Microsoft Visual Basic - Normal." This means you are working on the Normal template project.
  3. Choose Class Module from the Insert menu. This adds a class module to the project, typically named Class1, Class2, etc.
  4. Using the Properties window (lower left corner of the Editor), change the name of the new class module to AppEvents.
  5. In the Editor Window, type or paste the following:
  6. Option Explicit
    ' Declare a global object variable to represent the
    ' Word Application object for accessing Application events
    Public WithEvents WordApp As Word.Application
    Private Sub WordApp_DocumentChange()
    ' The procedure that will automatically run when
    ' the DocumentChange event is triggered
        Call MyModule.WindowTitleWithPath
    End Sub
    

    With this foundation in place, you are ready to make sure the WordApp object is registered whenever Word is started. The way to do this is to set up an AutoExec macro which is automatically run every time Word is started. You can do this by following these steps:

  7. Choose Module from the Insert menu. This adds a regular module to the project, typically named Module1, Module2, etc.
  8. Using the Properties window (lower left corner of the Editor), change the name of the new module to MyModule. (You can use a different name, if desired. If you do change the name, then you need to also change the MyModule reference in step 5, above.)
  9. In the Editor Window, type or paste the following:
  10. Option Explicit
    ' Set up an instance of AppEvents ready to access Application's events
    Public cAppEvents As New AppEvents
    
    Public Sub AutoExec()
    ' Automatically runs when Word starts
        ' Initialize the WordApp object in AppEvents class
        ' setting it to equal the Word.Application object
        Set cAppEvents.WordApp = Word.Application
    End Sub
    
    Public Sub WindowTitleWithPath()
    ' Changes window title to include path with filename
        ' Check if any child windows open (avoid error if no active window)
        If Windows.Count > 0 Then
            ' Change the window's caption
            ActiveWindow.Caption = ActiveDocument.FullName
        End If
    End Sub
    

    The final part of making this customization to Word is to make sure that the title bar is updated when you save your file. You do this by replacing (with macros) the built-in FileSave and FileSaveAs commands. You can do that by adding the following code to the MyModule module:

    Public Sub FileSave()
    ' Replaces the built-in FileSave command
        ' Check if path is empty string
        If ActiveDocument.Path = "" Then
            ' If new document is not saved yet, call FileSaveAs
            Call FileSaveAs
        Else
            ' Existing document is already on disk; just save it
            ActiveDocument.Save
        End If
    End Sub
    
    Public Sub FileSaveAs()
    ' Replaces built-in FileSaveAs command
            ' Use the Show method for the built-in FileSaveAs dialog box
            Dialogs(wdDialogFileSaveAs).Show
            ' Now run the code to change the window title
            Call WindowTitleWithPath
    End Sub
    

    When these macros are all entered, you should close Word and restart it. The title bars should all be updated to the full path names.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1248) applies to Microsoft Word 97, 2000, 2002, and 2003.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Relative References within Named Ranges

Excel is usually more flexible in what you can reference in formulas than is immediately apparent. This tip examines some ...

Discover More

Getting Word to Remember the Default Date and Time Format

One way to insert the current date into your document is to use the Date and Time dialog box. The Default button in the ...

Discover More

Retrieving Worksheet Names

Want to grab the names of all the worksheets in a workbook? Here's how you can stuff all those names into the cells of a ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (menu)

Working with Other People's Files

When you get files from other people, you may want a quick way to apply your formatting to their text. Provided that the ...

Discover More

Changing the Default File Name

When you first save a new file, Word bases the name of that file on the contents of the start of the first paragraph in ...

Discover More

Renaming a Document

Want to rename a document that is already on your hard drive? You can, of course, do it in Windows, but you can also do ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five more than 3?

2021-01-30 18:21:45

Rohn S, MVP 2012-2018

I just confirmed that this command still works with Office 365, and files saved in OneDrive. You may want to publish a "ribbon" version of this tip.

PS: the OneDrive path name is unreadable MS carp, but at least the user will know it is onedrive, if not the specific one if they have more than one OneDrive account, ie Consumer and Business.
.


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.