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.

Adding a File Path and Filename

by Allen Wyatt
(last updated December 29, 2018)

2

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:

  1. Select the worksheet whose header or footer you want to change.
  2. Display the Page Layout tab of the ribbon.
  3. Click the small icon at the bottom-right of the Page Setup group. Excel displays the Page Setup dialog box.
  4. Make sure the Header/Footer tab is displayed.
  5. Click on either the Custom Header or Custom Footer buttons, as desired. Word displays either the Header or Footer dialog box. (See Figure 1.)
  6. Figure 1. The Header dialog box.

  7. Position the insertion point in the Left Section, Center Section, or Right Section boxes, as desired.
  8. Click on the Insert File Path button. (It looks like a file folder with a piece of paper sticking out.) Excel inserts the following code at the insertion point:
  9.      &[Path]&[File]
    
  10. Click on OK two times to close both dialog boxes.

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.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Using Executive Summaries

An executive summary for a longer document may be a nice finishing touch. One of the lesser-known features of Word is ...

Discover More

Quickly Displaying the Page Setup Dialog Box

The Page Setup dialog box is indispensable in setting up the overall look of your document. You can display the dialog ...

Discover More

Combining and Formatting Times

Excel allows you to store times in your worksheets. If you have your times stored in one column and an AM/PM indicator in ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Creating a Dated Backup File

As you are developing your workbooks, you might want a way to automatically create backup files that include a date and ...

Discover More

Grabbing the MRU List

Excel keeps track of the most recent workbooks you've used. If you want to access that information in a macro, you'll ...

Discover More

Jumping Around Folders

When you open a workbook in Excel, the Open dialog box always starts within the folder in which you were last working. ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is nine more than 3?

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


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.