workbook and sheet name via formula

Brass Contributor

I have a standard header I put on almost every excel workbook I create I have been using for years. It includes several standard items, including Workbook name and Worksheet name, which are extracted via CELL("Filename",A1) formula. 


For Excel workbooks that are being viewed in Excel Online, however, whether through onedrive, sharepoint, or whatever, this formula yields a #VALUE! error. When I open in desktop, it renders fine, just not when looking at browser window. 


Is there an alternative that I can use to display current workbook and worksheet names via a formula in a cell that is compatible with Excel Online?

62 Replies


you need to create a Name like "SheetName" and use GET.CELL(32,A1) in the Refers To area. Whenever you need the sheet name you need to type "=SheetName" in the cell and you will get workbook and sheet name. 


This is a Excel 4 Macro and not being supported. You can use it in Names though.

best response confirmed by liverlarson (Brass Contributor)


Afraid for Excel Online that's only with Office Script, there are properties getName both for workbook and worksheet.


VBA and related functions don't work in Excel Online.



Read out the designation / name of the worksheet

Read out by formula

The focus of the formula solution is the CELL function (infotype; reference). In addition to the file name and the full path, the File Name infotype also returns the name of the worksheet. This is extracted using further functions so that only the sheet name is output at the end.

The result is achieved with these two formulas:
(formulas are from German Translate)
a) = PART (CELL ("filename"; A1); FIND ("]"; CELL ("filename"; A1)) + 1; 255)


b) = PART (CELL ("filename"; A1); FIND ("]"; CELL ("filename"; A1)) + 1; LENGTH (CELL ("filename"; A1)) - FIND ("]"; CELL ("filename"; A1)))

2. Read out via VBA

The following VBA function reads out the sheet name via VBA and displays it in a cell. To do this, enter the following code in a code module.


Public Function sheetname () As String
sheetname = ActiveSheet.Name
End function


If you now enter the function = sheetname () in a cell, the sheet name is read out and output in the corresponding cell.



I would be happy to know if I could help.



I know I don't know anything (Socrates)


* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here.

@NikolinoDE , VBA doesn't work with Excel Online

You are right, I disregarded the labels :(

@SergeiBaklan Hmm, wasn't aware of office scripts. From my 30 seconds of research it looks like they are 1) pretty new, 2) basically VBA/macros for online


If I did an office script to accomplish this functionality, does that in any way translate to the workbook when I download it?


Such a simple thing. Seems weird to have to use an online-specific solution. As an aside, do you happen to know why CELL doesn't work online?



Does Office 365 Excel support VBA?


All versions of Windows desktop Excel from Excel 5 through Excel 2019 support VBA.

This includes the version of Excel installed by Office 365. ...

There is no version of Excel Online, iOS Excel or Android Excel that supports VBA.

Nor does any version of Excel that runs on Windows RT support VBA.


In my humble opinion, it would be good to always have the possibility of VBA in Excel.

All new options such as editing PDF and cloud options, in all future versions, will be require VBA.

Unless someone has already adjusted to Java script ... which I don't hope.


What I don't know is, if you maybe can open from the Developer tab in Visual Basic editor, I don't have Office 365 yet. You can try it, maybe…maybe it will work.

The sequence is in Excel 2016

     Click File

     Click Options

     Click Customize Ribbon

     Under the list of Main Tabs, select Developer

     Click OK

The Developer tab will now appear on the Ribbon and from it you can open the Visual Basic Editor.

 If opening the Developer tab and clicking a button is a little too much work, you can also open the editor with the keyboard shortcut Alt+F11, which works whether the Developer tab is enabled or not.

As I told you before, with the logic of Excel 2016.



I know I don't know anything (Socrates)


You are right, Office Script is relatively new functionality available only for targeted tenants, that means not for everyone so far. And yes, basically they have the same role as VBA/macro for desktop versions, but that's totally different technology. Since the engines which runs online and desktop versions are different.


Back to question, Excel Online has limited functionality compare to desktop version which, however, is expanded quite fast. To my knowledge there is no built-in function which allows to return file/sheet name. 

yeah, VBA is supported in O365 - this question is specific to Excel documents being intereacted with through a web browser (Excel online) though.

The CELL function which works on desktop does not work with online (weirdly), and same is true of VBA.

It's a pretty small detail (CELL formula not working online), not a critical functionality, just annoying to me, because I literally use the same header on every document as a matter of best practice.


- you may always check if function available for online version or not here Excel functions (alphabetical) In particular,  what it says for CELL


- you may vote for the idea to add CELL() for the online version here CELL function added to online . In theory more votes more chances it'll be added.  

- Perhaps one day functionality of desktop and online versions will be synced, at least that's how I understand Microsoft intention. But with that most probably not VBA will go online but Office Script will go on desktop. That's a long way.

@NikolinoDE Before moving to Office 365 I used this function to include the workbook name in the Heading of the Workbook (not in the header) so new versions automatically pick up the right name. It almost works in 365, using =MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-6) but as soon as I open a 2nd workbook it changes the content of the cell in the 1st workbook to the filename of the newly opened workbook. Very frustrating and confusing!




ExcelApplication features Excel for the web Excel desktop app
Accessibility CheckerYesYes
Add background color to sheet tabsYesYes
Add hyperlinksYesYes
Advanced time filtering (Timeline slicer)NoYes
Apply conditional formattingYesYes
Apply smart/recommended formattingNoYes
Audio notes recordingNoYes
Cell references in formulasYesYes
Comment creationYesYes
Copy and pasteYesYes
Create external data connections2No3Yes
Create tablesYesYes
Creation of advanced analysis views (Power View, Power Pivot, Slicers)NoYes
Data validationYesYes
Drag and drop cellsYesYes
Duplicate (copy) worksheetsYesYes
Embed workbook on web or blog page (OneDrive)YesNo
External referencesNo4Yes
Fill handleYesYes
Font and cell formattingYesYes
Formula barYesYes
Formula tools, advancedNoYes
Freeze panesYesYes
Full fidelity reading viewYesYes
Functions YesYes
Group dataYesYes
Hide/unhide rows, columns, and sheetsYesYes
Insert chartsYesYes
Insert/delete rows and columnsYesYes
Insert picturesYesYes
Insert shapesYesYes
Merge cellsYesYes
Named rangesYesYes
Number formattingYesYes
Office Add-insYes5Yes
Offline viewing and authoringNoYes
Post to social network and present onlineNoYes
Power Pivot viewingYesYes
Power View viewingYesYes
Real-time co-authoringYesYes
Recommended chart creation and editing with formatting controlsNoYes
Refresh existing data connectionsYesYes
Remove duplicate valuesYesYes
Rename and add sheetsYesYes
Rename file while workbook is openYesNo
Rights management: IRM and password securityNoYes
Save or download a copyYesYes
Sheet protectionYesYes
Sort and filter dataYesYes
Spreadsheet audit and complianceNoYes
Status bar aggregatesYesYes
Tell MeYesYes
Text formattingYesYes
Total dataYesYes
Undo and redoYesYes
VBA and macro scriptingYes3Yes
View 3D chartsYesYes
What if analysis toolsNoYes


Feature availability


Thank you for your patience and time.


Wish you a nice day / night with lots of health, joy and love.



I know I don't know anything (Socrates)


You may vote here CELL function added to online  for this function. More votes sooner it could appear. 

To get the Sheetname in Excel Online: In another Sheet (e.g. Sheet2)
Result of C1: Sheet1!

The result of C1 can be used in Formulas such as INIDIRECT (…) and adapts automatically if sheet1 is renamed.
And of course, you can place this workaround on a technical hidden sheet (sheet2 in this example) , and display the result on the current sheet, if you really need the current sheet name
Strange thing is that it works momentarily when you open the spreadsheet, displaying the correct value, before reverting to #VALUE!


If you had some value in last saved in desktop version file, it is shown in Online version from cache till you recalculate worksheet. After that an error.

Thank you! I had to replace the semicolons with commas for it work on the desktop and online versions, but besides that this is a good workaround


You may sync online regional settings with your local one in File->Options->Regional Format Settings


Thanks to the help above the following formula worked for me.

CELL("filename",A1)  returns the full path filename and worksheet name with the work book in square brackets []

LEN (string) gives the length of a string

FIND (string1string2)returns the position from the left of the first occurrence of string1 in string2

RIGHT(string ,n) gives the last n characters counting from the right.

1 best response

Accepted Solutions
best response confirmed by liverlarson (Brass Contributor)


Afraid for Excel Online that's only with Office Script, there are properties getName both for workbook and worksheet.


VBA and related functions don't work in Excel Online.

View solution in original post