KutoolsforOffice — One Suite. Five Tools. Get More Done.February Sale: 20% Off

AuthorXiaoyangLast modified

How to insert a file name or path into the cell/header or footer in Excel?

When working with multiple Excel workbooks or preparing reports for distribution, it's often valuable to display the current workbook's file name, full file path, or even the active worksheet name directly within your Excel file—either in a cell, header, or footer. This can improve document organization, version tracking, and provide clarity for collaborators or recipients. Excel offers several practical ways to insert these details, whether you want a one-time snapshot or need the information to update dynamically as your file changes. Below, you'll find step-by-step guidance for common methods, along with tips for troubleshooting and optimizing your workflow.

Insert the current file name or path in a cell with Formula

Insert the current file name or path in the cell/header or footer with Kutools for Excel good idea3

Insert the current file name or path in the header/footer with the Header & Footer function

VBA Code - Programmatically insert file name or path into cell, header, or footer


Insert the current file name or path in a cell with Formula

If you want to display the file name, file path, or worksheet name in a cell—allowing for dynamic referencing as the workbook is moved or renamed—Excel formulas provide a flexible and convenient approach. This is especially useful when you need the information to update automatically after saving or relocating your file. The following table presents formulas for different scenarios:

ItemFormulaExample
Filename only=MID(CELL("filename"), SEARCH("[", CELL("filename"))+1, SEARCH("]", CELL("filename"))-SEARCH("[", CELL("filename"))-1)products features.xlsx
Filepath only=LEFT(CELL("filename",A1), FIND("[", CELL("filename",A1),1)-1)C:\Users\dt\Desktop\New folder\
Active sheet name only=RIGHT(CELL("filename"), LEN(CELL("filename"))-FIND("]", CELL("filename"),1))Sheet7
Current filename, filepath, and active sheet name=CELL("filename")C:\Users\dt\Desktop\New folder\[products features.xlsx]Sheet7

Instructions and notes for use:

• To use these formulas, simply copy the one corresponding to the item you want and paste it into your target cell (for example, B1). Once entered, press Enter to display the information.

• If you're copying to other cells, you can drag the cell's fill handle or use copy-paste as usual. For consistent results, keep reference cells (such as A1) unchanged, or adjust them as needed.

• Please note: these formulas will only return results if your workbook has been saved at least once, as the file path and name require a file location. Unsaved workbooks will yield a blank return.

• Should you move or rename the workbook, formulas will update automatically after re-saving.

• In case of formula errors (such as #VALUE!), verify the workbook has been saved and your formula syntax matches exactly.

• Keep in mind that formulas display live file properties and are suitable for most reporting needs, but do not affect header or footer areas.


Insert the current file name or path in the cell/header or footer with Kutools for Excel

Kutools for Excel’s Insert Workbook Information feature streamlines the process of displaying your file’s name, path, or worksheet name directly in cells, headers, or footers. This handy utility is ideal for anyone needing a quick, flexible solution—for example, preparing documentation that requires consistent branding or tracking workbook versions across a team.

Kutools for Excel offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Itegarate with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

To use this feature once Kutools for Excel is installed, do the following:

1. Click Kutools Plus > Workbook Tools > Insert Workbook Information. See screenshot:

click Insert Workbook Information feature of kutools

2. In the Insert Workbook Information dialog box, select which information you wish to insert, such as worksheet name, workbook name, workbook path, or both; choose whether to display it in cells, headers, or footers; and specify the target location (Left, Center, Right for headers/footers, or select target cell for cell insertion). See screenshot:

set options in the dialog box

3. Click OK to finish. For cell insertion, the selected workbook information will appear in the specified cell instantly. For header or footer insertion, preview the result via View > Page Layout if needed. See examples:

insert the wotkbook information by kutools

The Kutools method supports both simple and complex file information placement, and is recommended for those who prefer graphical tools without manual formula or code entry. If you want the file properties to update on workbook changes, reapply the function after renaming or moving the file.

If you insert the information into a header or footer, you may select the insertion point—Left, Center, or Right. Double-check your choice for clarity, especially in printed documents. For batch updates (multiple sheets), simply repeat the operation for each worksheet as needed. Avoid direct editing of header/footer codes without using the tool for best results.


< Insert the current file name or path in the header/footer with the Header & Footer function

Using Excel's built-in Header & Footer function is a straightforward way to add a file name, file path, or sheet name to printed output. This presents static information and is effective for branding, version control, or reference in reports and distributed documents.

• On the Ribbon, click Insert > Header & Footer. The worksheet switches to the Page Layout view, where the header/footer editing boxes appear at the top and bottom of the page.

• In the Header or Footer section, select your desired area—Left, Center, or Right. Then, on the Design tab (Header & Footer Tools), choose File Path, File Name, or Sheet Name depending on your requirement. See screenshot:

click File Path, File Name or Sheet Name under the Design tab

• After adding the code, click any cell to exit the design mode. Your selection is visible in the header or footer for the worksheet and will print with the output. See examples below:

Insert the file path into the header
Insert the file path into the header
Insert the file name into the footer
Insert the file name into the footer

Tips: The built-in feature works best for individual sheets. It does not update dynamically for multiple workbooks or when using unsaved files. To batch-apply across several sheets, switch to each sheet and repeat the process, or consider using VBA for automation.


< VBA Code - Programmatically insert file name or path into cell, header, or footer

For users who require automated, batch updates or need to add file properties across multiple sheets or workbooks, VBA offers a practical solution. By leveraging a simple script, you can instantly populate a cell, header, or footer with file information and even set it to update whenever the workbook is opened or saved. This method is especially suitable for regular reporting, shared templates, or complex document workflows where manual methods become tedious.

Below are examples of VBA applications for different scenarios. Before starting, save your workbook and enable the Developer Tab in Excel.

How to use VBA to insert file information:

1. Click Developer > Visual Basic. In the Microsoft Visual Basic for Applications window, select Insert > Module.

2. Paste the following code into the Module window, depending on your target (cell, header, or footer):

Insert file name into a specific cell (e.g., A1):

Sub InsertFileNameToCell()
    Dim fileName As String
    fileName = ThisWorkbook.Name
    Range("A1").Value = fileName
End Sub

To run the code, click the Run button Run button in the VBA editor. The current file name will populate cell A1. To change the destination, modify Range("A1") to your preferred cell.

Insert file path into worksheet header (center position):

Sub InsertFilePathToHeader()
    Dim filePath As String
    filePath = ThisWorkbook.FullName
    ActiveSheet.PageSetup.CenterHeader = filePath
End Sub

After entering the code, click Run in the VBA editor. Check the sheet's Page Layout view to see the inserted file path in the center header. If you need to set Left or Right header, use .LeftHeader or .RightHeader respectively.

Insert file name into the footer (right position):

Sub InsertFileNameToFooter()
    Dim fileName As String
    fileName = ThisWorkbook.Name
    ActiveSheet.PageSetup.RightFooter = fileName
End Sub

When executed, the current file name will appear as the right footer in the active worksheet. Adjust .LeftFooter or .CenterFooter to suit your needs.

Tips and troubleshooting:

  • For batch operations across multiple sheets, loop through Worksheets in your VBA code.
  • If you receive a permission error, confirm the workbook is not protected and macros are enabled.
  • Use On Error Resume Next to bypass errors if applying to multiple sheets with varied settings.
  • For automatic updates, assign macros to Workbook events such as Workbook_Open or Workbook_BeforeSave.
  • Always save a backup before running VBA macros, especially when bulk updating headers or footers.

Using VBA provides strong flexibility and scalability. It is recommended if you need regular, automated updates or wish to apply file details in bulk across several files or sheets. For first-time macro users, always enable macro content and check your macro security settings.


In summary, whether you choose formulas, Kutools, Excel’s header/footer features, or VBA automation, the method depends on your workflow needs, frequency of updates required, and whether batch operations are necessary. Most errors stem from unsaved files, protected sheets, or disabled macros; check these before troubleshooting further. For everyday use, the formula and Kutools approaches offer speed, while VBA is most effective for automation and scalability.

Best Office Productivity Tools

🤖Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |  Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |  Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!

All Kutools add-ins. One installer

Kutools for Office suite bundles add-ins for Excel, Word, Outlook & PowerPoint plus Office Tab Pro, which is ideal for teams working across Office apps.

ExcelWordOutlookTabsPowerPoint
  • All-in-one suite — Excel, Word, Outlook & PowerPoint add-ins + Office Tab Pro
  • One installer, one license — set up in minutes (MSI-ready)
  • Works better together — streamlined productivity across Office apps
  • 30-day full-featured trial — no registration, no credit card
  • Best value — save vs buying individual add-in