
Tips.Net > ExcelTips Home > Files > Adding a File Path and Filename
Summary: Do you need to add a files’ path and name to your workbook? There are a couple of ways you can go about adding the information, either to an existing cell or to a header/footer. This tip explains all the approaches you can use. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, and Excel 2003.)
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 right 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, if you are using Excel 2002 or Excel 2003:
&[Path]&[File]
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 Excel 2002 and Excel 2003. 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.
Tip #2875 applies to Microsoft Excel versions: 97 2000 2002 2003
Organize Your Data! Using the powerful sorting capabilities of Excel can help you get your data into just the order you need. Find out how you can use the full capabilities of sorting to your benefit.
Check out ExcelTips: Serioius Sorting today!
It doesn't matter if you are a beginner or expert, the ExcelTips archives are the fastest way to improve your productivity. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site