by Allen Wyatt
(last updated January 30, 2021)
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:
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.)
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:
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.
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.
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!
Got a lot of open documents you are working with? You can save them all at one time by just holding down the Shift key ...Discover More
Hidden text is a great boon if you want to make sure something doesn't show up on the screen or on a printout. If you ...Discover More
Double-click a Word document on your desktop, and you expect Word to spring into action and load the document. What if ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.