Excel.Tips.Net ExcelTips (Menu Interface)

Adding a File Path and Filename

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.

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:

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:


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 = _
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.

Related Tips:

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!


Leave your own comment:

  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*What is 5+3 (To prevent automated submissions and spam.)
           Commenting Terms

Comments for this tip:

WILLIAM    07 Jul 2016, 06:31
Noel Hempseed    10 Mar 2016, 07:36
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 E\My Data\Excel etc in the worksheet so that it would print out at the foot of the worksheet.

Noel Hempseed

March 10, 2016
jackster    26 Jan 2016, 08:15
Great site! Kudos!!! So much better than Microsoft's obtuse Help :)
Thanks for a nice contribution to all of us out here!
David    02 Dec 2014, 15:09
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?
Michael (Micky) Avidan    24 Oct 2014, 07:56
("úøùéí 1") should read: ("Chart 1").
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
Michael (Micky) Avidan    24 Oct 2014, 07:25
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)
Garry    23 Oct 2014, 05:37
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?
Michael (Micky) Avidan    22 Oct 2014, 09:13
Try to run the following Macro:
Sub User_Name_Chart_Title()
    For Each CH In ActiveSheet.ChartObjects
        ActiveChart.HasTitle = True
        ActiveChart.ChartTitle.Text = "User Name: " & Environ("username")
End Sub
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
Garry    21 Oct 2014, 23:45
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.
Michael (Micky) Avidan    15 Aug 2014, 07:22
What is the EXACT function you are using ?
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
naveen    14 Aug 2014, 08:58
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.
Chuck    10 Nov 2013, 21:50
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?
barry    02 Nov 2013, 12:21
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

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us


Advertise with Us

Our Privacy Policy

Our Sites


Beauty and Style




DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)



Home Improvement

Money and Finances


Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives


Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.