Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Adding a File Path and Filename.
by Allen Wyatt
(last updated December 29, 2018)
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.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11356) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Adding a File Path and Filename.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
When you open a workbook in Excel, the Open dialog box always starts within the folder in which you were last working. ...Discover More
Does your macro need to add information to the end of a text file? This is called appending and is done using the ...Discover More
Want to make your importing of text data faster than ever? Here are some ideas you can apply right away.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 ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.