Full Path Names in Headers or Footers

Written by Allen Wyatt (last updated August 4, 2018)
This tip applies to Excel 97, 2000, 2002, and 2003


Excel allows you to insert many different items in the header or footer of your spreadsheet (as you can see in other ExcelTips). Unfortunately, one of the items you cannot easily add is the full path name of your spreadsheet file. You can, however, add the path name to the header or footer by using a macro, such as the following one:

Sub DoPath()
'   Inserts the file name and path in the footer
'   of each worksheet in the active workbook
    For Each sheet In ActiveWorkbook.Sheets
        sheet.PageSetup.CenterFooter = ActiveWorkbook.FullName
    Next sheet
End Sub

To use this, simply run it and it adds the full path and file name for your spreadsheet file into the center section of the footer. It does this for every worksheet in your workbook. If you want the information added to a different place in the footer or header, you simply replace the CenterFooter portion of the macro with one of the following: LeftFooter, RightFooter, LeftHeader, CenterHeader, or RightHeader.

As noted, the above macro changes the header or footer for each worksheet in your workbook. If you only want to change the current worksheet, you can use the following abbreviated version of the macro:

Sub DoOnePath()
'   Inserts the file name and path in the footer
'   of the active worksheet
    ActiveSheet.PageSetup.CenterFooter = ActiveWorkbook.FullName
End Sub

You should note that unlike other items you stick in the header or footer, the path and file name inserted by these macros are not "dynamic." Thus, if you move the spreadsheet file to a different directory or save it under a different name, you need to run the macro again.

While the above solutions work just fine in all versions of Excel, if you are using Excel 2002 you should know that there is an even easier way to add the path name to the header or footer. Microsoft finally heard the requests of users, and added a button to the Header and Footer dialog boxes that allows you to insert both the path and file name of a workbook. Follow these steps:

  1. Select the worksheet whose header or footer you want to change.
  2. Choose Page Setup from the File menu. Excel displays the Page Setup dialog box.
  3. Make sure the Header/Footer tab is selected. (See Figure 1.)
  4. Figure 1. The Header/Footer tab of the Page Setup dialog box.

  5. Click on either the Custom Header or Custom Footer buttons, as desired. Word displays either the Header or Footer dialog box. (See Figure 2.)
  6. Figure 2. The Header or Footer dialog box.

  7. Position the insertion point in the Left Section, Center Section, or Right Section boxes, as desired.
  8. Click on the File button. (It looks like a file folder with a piece of paper sticking out.) Excel inserts the following code at the insertion point:
     &[Path]&[File]
  1. When you print the worksheet, Excel replaces the codes with the path name and the file name of the workbook, respectively.
  2. Click on OK two times to close both dialog boxes.

Unlike the macro solution provided earlier in this tip, the new header and footer codes provided in Excel 2002 are dynamic. If you rename or relocate your workbook file, the information in the header or footer will change the next time you print.

Note:

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

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2639) applies to Microsoft Excel 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

Displaying a Single Page

When displaying the information in your document, Word is rather flexible. It can, if you so choose, display multiple ...

Discover More

Quickly Duplicating Drawing Objects

Excel provides a couple of different ways that you can quickly duplicate drawing objects in a worksheet. Committing these ...

Discover More

Applying the All Caps Format

Want your text to always appear in uppercase, regardless of how you type it? Word allows you to add formatting to your ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (menu)

Creating Long Page Footers

Ever wish that you could create nice, long footers that appear at the bottom of each page when you print your worksheet? ...

Discover More

Moving Part of a Footer Down a Line

Setting up a single footer line for your printouts is fairly easy. If you want to move part of the footer down a line so ...

Discover More

Creating a Footer

Adding a predefined footer to your worksheets is easy, and it helps convey valuable information when you make a printout. ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, 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 nine minus 5?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

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

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, 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.