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

Adding Vertical Lines Between Columns

Columns can be an integral part of your document layout. In some instances you may want Word to insert a vertical line ...

Discover More

Getting Rid of Fixed Objects

Some dialog boxes in Excel refer to "fixed objects" in worksheets. What are they and how do you get rid of them?

Discover More

Understanding Views

Need to display your worksheet in different ways? A quick way to do this is to create views, as described in this tip.

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (menu)

Saving Worksheets in Lotus 1-2-3 Format

You can export an Excel worksheet in a variety of formats. One of those formats is Lotus 1-2-3, which is available as an ...

Discover More

Odd Behavior when Opening a Shared File with a Shortcut

Tracking down a problem that occurs with a single workbook can be vexing. One such problem occurred with Chris, and these are ...

Discover More

Opening Non-Excel Files

Not all data is created in Excel. Indeed, you may have data in files created by many other types of programs. You might be ...

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 9 - 2?

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.