Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Adding a File Path and Filename.
Written by Allen Wyatt (last updated November 7, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003
Margo wants to insert a file path and filename in an Excel worksheet. She wants to be able to insert the information in either a cell or into the header/footer. This is rather easy to do in Excel.
To insert the file path and filename into a cell, you use the CELL worksheet function in the following manner:
This formula returns the entire path, filename, and tab name of the current worksheet, like this:
If you want to strip out the brackets and the sheet name, you can use the following variation on the formula:
The LEFT function gets rid of everything from the right bracket to the end of the string, while the SUBSTITUTE function gets rid of the left bracket.
Putting a path and filename into a header or footer is easy:
Figure 1. The Header dialog box.
When you print the worksheet, Excel replaces the codes in step 5 with the path name and the file name of the workbook, respectively.
If you are using Excel 97 or Excel 2000, then the above steps won't work. Instead, you need to use a macro to insert the path and filename:
Sub DoFullPath() ActiveSheet.PageSetup.CenterFooter = _ ActiveWorkbook.FullName End Sub
This macro will also work in later versions of Excel. To specify a different place for the path and filename, simply change CenterFooter to another location (such as LeftFooter, RightFooter, LeftHeader, CenterHeader, or RightHeader). If you decide to use the macro approach, you will need to remember to run it every time that you change either the workbook's filename (you use Save As), or you change the place where the workbook is stored on your disk.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2875) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Adding a File Path and Filename.
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!
Did you know that if you create a link that uses a UNC path, Excel could rewrite that path to something entirely ...Discover More
The Open dialog box allows you to sort the files it presents to you. How you do the sorting depends on the version of ...Discover More
Open a workbook that someone else is working on, and you won't be able to save your changes back into the same file. ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.