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.

Adding a File Path and Filename

by Allen Wyatt
(last updated July 13, 2013)

14

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. Choose the Page Setup option from the File menu. Excel displays the Page Setup dialog box.
  3. Click on either the Custom Header or Custom Footer buttons, as desired. Word displays either the Header or Footer dialog box. (See Figure 1.)
  4. Figure 1. The Header dialog box.

  5. Position the insertion point in the Left Section, Center Section, or Right Section boxes, as desired.
  6. Click on the File button. (It looks like a file folder with a piece of paper sticking out.) Excel inserts the following code at the insertion point:
  7.      &[Path]&[File]
    
  8. 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.

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.

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

Printing Close to the Edge

Word allows you to specify all sorts of paper sizes and margins for your documents. If your margins result in trying to print ...

Discover More

Printing Portions of Mail Merged Documents

When you use a data source to create a bunch of documents in a mail merge, you might not want to print all the documents ...

Discover More

Replacing a Colon in a Sequence

Sometimes you'll run across the need to replace a very specific sequence of characters in your document. It is for these ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (menu)

Getting Input from a Text File

You can use a macro to read information from a text file. The steps are easy, and then you can use that information in any ...

Discover More

Saving in Two Locations

When you save a workbook to disk, you may want to automatically save a duplicate workbook in a separate location. This can be ...

Discover More

Don't Update Links to Other Programs

If you have links in your workbook to data in other workbooks, you may want to control whether Excel updates those links or ...

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. 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 minus 5?

2017-04-07 17:31:23

Guest User

BEST TIP! Literally just copied and pasted the formula and it worked flawlessly. So easy to follow! THANK YOU!


2016-07-07 06:31:35

WILLIAM

EXCELLANT TIP. WORKS PERFECTLY AND SAVED ME LOTS OF TIME


2016-03-10 07:36:21

Noel Hempseed

I am not that excel savvy. I do not follow the example.Would it be possible to illustrate simply what areas of the worksheet I would go to to put the EMy DataExcel etc in the worksheet so that it would print out at the foot of the worksheet.
Thanks,

Noel Hempseed

March 10, 2016


2016-01-26 08:15:26

jackster

Great site! Kudos!!! So much better than Microsoft's obtuse Help :)
Thanks for a nice contribution to all of us out here!


2014-12-02 15:09:10

David

I would like to customize a header for a worksheet so that I do not have to manually change it every quarter when I print a (quarterly financial)report. The four options would be First Quarter, Second Quarter, Third Quarter, and Fourth Quarter. I already have dates in the worksheet and ideally would like it to read off of that. E.g., if the date is 9.30.xx, then it would automatically print with Third Quarter. If it was 12.31.xx, then it automatically print Fourth Quarter. Can this be done?


2014-10-24 07:56:52

Michael (Micky) Avidan

("úøùéí 1") should read: ("Chart 1").
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL


2014-10-24 07:25:07

Michael (Micky) Avidan

@Garry,
Insert a TextBox under the X Axis and run the following Macro:
-------------------------------
Sub User_Name_Chart_Title()
ActiveSheet.ChartObjects("úøùéí 1").Activate
ActiveChart.Shapes.Range(Array("TextBox 1")).Select
With Selection.ShapeRange.TextFrame2.TextRange
.Characters.Text = "User Name: " & Environ("username")
.ParagraphFormat.Alignment = msoAlignCenter
End With
End Sub
---------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL


2014-10-23 05:37:19

Garry

Thanks Micky,

I will work on this approach. I don't want to make the user's name equal to the chart title; I just want it to appear buried down in the footer area, near the date, time, path and file name.

Is there an equivalent term to "ActiveChart.ChartTitle.Text" but just for the Footer area? ActiveChart.Footer.Center.Text?


2014-10-22 09:13:36

Michael (Micky) Avidan

@Garry,
Try to run the following Macro:
-------------------------------
Sub User_Name_Chart_Title()
For Each CH In ActiveSheet.ChartObjects
CH.Activate
ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Text = "User Name: " & Environ("username")
Next
End Sub
-----------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL


2014-10-21 23:45:37

Garry

How can I add a user's name into the footer of an Excel chart? In other words, is there an "&[User]" element code, similar to &[Path], &[File], &[Date], etc.? This would be particularly useful in identifying charts printed from shared network files.


2014-08-15 07:22:07

Michael (Micky) Avidan

@naveen,
What is the EXACT function you are using ?
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL


2014-08-14 08:58:34

naveen

when i am using filename function in excel 1 (this is the filename) , and then i open excel 2, the cell in excel 1 changes from "excel 1" to "excel 2".

Please advise, how to prevent this.


2013-11-10 21:50:04

Chuck

In Excel 2003, I have added =CELL("filename")in cell A1 to all sheets of a workbook. The sheet name provided by this function does not change when I make a different sheet the active one. After making the different sheet the active one, I can change the sheet name by hitting F2. Is there a way to cause the sheet name to change when I activate a different sheet within the book?


2013-11-02 12:21:31

barry

how do i keep a filepath in the footer of an excel worksheet even when email the wsheet to someone.
When emailing it changes the path to the temporary file linked to emails


This Site

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.

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.