Return to Excel Formulas List

Insert File Name – Excel Formula

Download Example Workbook

Download the example workbook

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

insert-file-name-formula-Main-Function

Get File Name

In Excel there isn’t a function to get the file name directly. However, the CELL Function will return the file path, name, and sheet. Using the text functions FIND and MID, you can extract just the file name.

Get File Name

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.

filename

FIND the File Name Position

As shown above, the CELL Function returns the file path, name, and worksheet. We don’t need the path and the worksheet name, so we use the FIND Function to determine the position of the character immediately before (“[“) and after (“]”) the file name.

This first formula will look for “[“. We add one to the first position to start after the first square bracket (“[“).

First Position

Next we will calculate the position of the “]” to determine where the file name ends.

Last Position

Take the difference to find the length of the file name:

Length

MID Function

Now we have the starting position and the length of the file name. We plug these results into the MID function to extract the file name from the file path, name, and worksheet string.

File Name

Combing these steps into a single formula, we get:

Get File Name