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 DataExcel[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:
- Select the worksheet whose header or footer you want to change.
- Display the Page Layout tab of the ribbon.
- Click the small icon at the bottom-right of the Page Setup group. Excel displays the Page Setup dialog box.
- Make sure the Header/Footer tab is displayed.
- Click on either the Custom Header or Custom Footer buttons, as desired. Word displays either the Header or Footer dialog box. (See Figure 1.)
- Position the insertion point in the Left Section, Center Section, or Right Section boxes, as desired.
- 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:
- Click on OK two times to close both dialog boxes.
Figure 1. The Header dialog box.
&[Path]&[File]
When you print the worksheet, Excel replaces the codes in step 5 with the path name and the file name of the workbook, respectively.