Add the file path to Excel worksheet headers and footers

Applies to
Microsoft Excel 97 and 2000

When you print a worksheet in Excel, the header or the footer can include both the name of the worksheet and the name of the workbook. However, Excel does not provide a code for printing the full path (file location) of the workbook within the header or footer.

Using a small Microsoft Visual Basic® for Applications procedure (or macro), you can include the full path and file name in any section (left, center, or right) of either the header or footer. Of course, since you want to include the full path, the workbook must be saved to disk before you use the macro.

The following macro adds the current path and file name to the left footer of the active worksheet. The workbook must be saved before you can add any path information to the footer.

  UpdateFooter()ActiveSheet.PageSetup.LeftFooter = ActiveWorkbook.FullName
End Sub

To add the path and file name to the center or right section of the footer, change LeftFooter to either CenterFooter or RightFooter in the code. To add the information to the header, use LeftHeader, CenterHeader, or RightHeader.

Create this macro

Press ALT+F11 to start the Visual Basic Editor, and then click Module on the Insert menu. Enter the code from above, and then switch to the worksheet where you want to insert the path and file name. Run the macro (on the Tools menu, point to Macro, and then click Macro; the name of the macro is UpdateFooter), and then click Print Preview on the File menu to view the printout on screen to see if the path is in the correct location.

 Note    To make this macro available for any workbook you have open, you can assign it to a toolbar button. For more information about running a macro from a toolbar button, type add a macro to a toolbar in the Office Assistant or on the Answer Wizard tab in the Excel Help window, and then click Search.

Animated Icon To see an animated version of this procedure, click the link below.

Demo of procedure

More information