Home

MacOffice

This site will look better if you upgrade to a browser that supports web standards.

Put Filename and Path in header or footer

In XL98/2001/v.X (and in WinXL97/00), there is no provision for including the Drive path and filename in a header or footer. This is a common requirement in business applications, and was remedied in WinXL2002.

Manual Method

Here's a way to manually place the path and filename in the left-hand footer. Put the macro in your Personal Macro Workbook (Personal.xls for WinXL). Call the macro from the Tools/Macro/Macros... dialog, or attach the macro to a toolbar button or keyboard shortcut.

    Public Sub PathAndFileNameInFooter()
        Dim wsSht As Worksheet
        For Each wsSht In ActiveWindow.SelectedSheets
          wsSht.PageSetup.LeftFooter = ActiveWorkbook.FullName
        Next wsSht
    End Sub

Note that the macro cycles through every selected sheet, since the user may select more than one.

You can replace .LeftFooter with .LeftHeader, .CenterHeader, .RightHeader, .CenterFooter, or .RightFooter, depending on the desired placement. You can also concatenate formatting instructions using the header/footer formatting codes - see "Formatting codes for headers and footers" in XL/VBA help.

Automatic Method - Per Workbook

You can automate this task by putting this macro in the ThisWorkbook code module of your workbook The header or footer will be updated whenever the user chooses to Print or Print Preview:

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
        Dim wsSht As Worksheet
        For Each wsSht In ActiveWindow.SelectedSheets
          wsSht.PageSetup.LeftFooter = Me.FullName
        Next wsSht
    End Sub

Valid XHTML 1.1 Valid CSS Made on a Macintosh

Quick Links

Unfamiliar with macros? See David McRitchie's Getting Started With Macros and User Defined Functions

How to make all or new workbooks print the path and filename