Word.Tips.Net WordTips (Menu Interface)

Full Path Names in Word

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
            ' Existing document is already on disk; just save it
        End If
    End Sub
    Public Sub FileSaveAs()
    ' Replaces built-in FileSaveAs command
            ' Use the Show method for the built-in FileSaveAs dialog box
            ' 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.

    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.

    Related Tips:

    Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!


    Leave your own comment:

      Notify me about new comments ONLY FOR THIS TIP
    Notify me about new comments ANYWHERE ON THIS SITE
    Hide my email address
    *What is 5+3 (To prevent automated submissions and spam.)
               Commenting Terms

    Comments for this tip:

    Michael Lewis    15 Sep 2016, 10:13
    Thanks for the great instructions - this worked like a champ. The only thing I had to find was using F4 to turn on the properties window.
    Rohn MVP    27 Jan 2016, 03:39
    JUzel take a look at this tip:

    Limiting Directories in the FILENAME Field

    J Uzel    24 Apr 2014, 11:22
    Is there a method to truncate the full path name?
    The full path names of many files I work with are very long. I'm unable to change the folder names to make them shorter (that would be preferred).

    Example of full path (too long):
    Example of full path (truncated):

    If this is possible, please let me know. I been tweaking the code you provided, but without any luck.

    Mark Bunster    21 Nov 2013, 20:06
    Can you set it to other fields in the Word Doc? Specifically I'm trying to get it to show what's in the Title field of the Summary tab, since I have an app that calls open Word and inserts certain information. The actual title of the doc it creates is a number, which is confusing to users. If it can show the description of the doc as entered in the calling app and passed through to the Summary tab, that would be awesome. Thx
    Oriol Fortuny    18 Aug 2013, 06:56
    Sorry, I did do something wrongly. In the first step, I chose "Module" from the Insert menu instead of "Class Module".
    Oriol Fortuny    18 Aug 2013, 06:15
    First of all,thank you so much for your very useful tips.
    I´ve followed the steps to be able to see full path names in Word 2003, but when I open I get an error message from Visual Basic, namely in the line (Modules/AppEvents):

    Public WithEvents WordApp As Word.Application

    After changing "WithEvents" for "AppEvents", I open a Word document and Visual Basic highlights "WordApp" and shows a small window that says "Compile error: Expected: end of statement".

    I guess I must be doing something wrongly.



Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us


Advertise with Us

Our Privacy Policy

Our Sites


Beauty and Style




DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)



Home Improvement

Money and Finances


Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives


Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.