Written by Allen Wyatt (last updated December 29, 2018)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
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:
=CELL("filename")
This formula returns the entire path, filename, and tab name of the current worksheet, like this:
E:\My Data\Excel\[Budget.xls]Sheet1
If you want to strip out the brackets and the sheet name, you can use the following variation on the formula:
=SUBSTITUTE(LEFT(CELL("filename"),FIND("]",CELL("filename"))-1),"[","")
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.
&[Path]&[File]
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 Microsoft 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!
If you don't like the way that Excel exports information you intend to use with other programs, then your best bet is to ...
Discover MoreExcel keeps track of the most recent workbooks you've used. If you want to access that information in a macro, you'll ...
Discover MoreOpen a workbook that someone else is working on, and you won't be able to save your changes back into the same file. ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2018-12-29 11:39:08
Benjamin C Morin
To Insert File and Pathname Plus in the Header or Footer Screens--Excel 2016
I Insert a file and pathname (and other options) in the following way:
Click Insert Tab on the Ribbon
Find the Text Group
Click on Header & Footer button.
The Design Tab appears
Find the Header & Footer Elements group, and insert what you need in the Header area on the worksheet. Of course, the active cell is the Center cell but you may click on the Left cell and type (or insert) or go to the Right Cell and do the same.
When you are done, simply go back to the Norman View to ignore the greyed-out area.
I hope this helps. (Sorry my images did go through.)
Benjamin
2018-12-29 11:33:45
Benjamin C Morin
To Insert File and Pathname Plus in the Header or Footer Screens--Excel 2016
I Insert a file and pathname (and other options) in the following way:
Click Insert Tab on the Ribbon
Find the Text Group
Click on Header & Footer button.
The Design Tab appears
Find the Header & Footer Elements group, and insert what you need in the Header area on the worksheet. Of course, the active cell is the Center cell but you may click on the Left cell and type (or insert) or go to the Right Cell and do the same.
When you are done, simply go back to the Norman View to ignore the greyed-out area.
I hope this helps. (Sorry my images did go through.)
Benjamin
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments