Insert File Path in Excel

This tutorial will teach you how to get the path and file name using a formula in Excel.

insert path formula Main Function

Get Path and File Name

In Excel there isn’t a function to get the path and file name directly, but the CELL Function will return the file path, name, and sheet. Using the text functions FIND, LEFT, and SUBSTITUTE, we can isolate the path and file name.

Sheet1

Let’s step through the formula.

File Name, Path, and Worksheet

We use the CELL Function to return the file path, name, and sheet by entering “filename” as the info type.

Cell

AutoMacro - VBA Code Generator

FIND the File Name Position

As shown above, the CELL Function returns the file path, name, and worksheet. We don’t need the worksheet or the square brackets, so we use the FIND function to determine the position of the last character (i.e. the one before “]”) of the file name.

Find

Remove the Worksheet Name

Once we have the position of the file name’s last character, we use the LEFT Function to remove the name of the worksheet.

Left

SUBSTITUTE Function

You can see above that there is still an open square bracket between the path and file names. Use the SUBSTITUTE function to replace the “[“ with an empty string.

Substitute

Combining these steps into a single formula gives us:

 

Get Path Only

You might want to show the path only, without the file name. For this, we can stop at the LEFT Function with a little tweak. There’s no need to SUBSTITUTE since there won’t be any mid-string characters to delete. To return just the path, we find the position of the first character of the file name (“[“), instead of the last, and the path name is everything to the left.

File-Path

 

 

Excel Practice Worksheet

Practice Excel functions and formulas with our 100% free practice worksheets!

  • Automatically Graded Exercises
  • Learn Excel, Inside Excel!