- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the current workbook name in Excel?
A workbook is a type of document used to organize and manage data or information in a structured format. MS Excel is also an example of a workbook. It is categorized as a software application used to process and manipulate data. This tutorial provides two examples to obtain the current workbook name. The first method is based on the use of VBA code. This method allows the user to define a module, to obtain the required output. On the other hand, the second method is based on the use of Kutool plus extension.
Example 1 − To obtain the current workbook name in excel by using the VBA code.
Consider the below provided excel worksheet to understand the process to obtain the name of current workbook in excel by using the VBA code.
To open the VBA editor, click on the “Developer” tab, and then under the code section, choose “Visual Basic” code. As, depicted below:
This will open the “Microsoft Visual Basic Application” dialog box, as shown below
Go to the “Insert” tab and then click on “Module”.
This will open the below provided code area:
In the above code area, simply type the below given code, with proper indentations.
Code to copy:
' define function name with return type Function wrk_book_name() As String ' declare string variable to store ' current work book name ' active workbook is an instance of workbook ' name will return the name of active workbook wrk_book_name = ActiveWorkbook.Name ' below instruction will indicate the 'end of defined function End Function
Press “ctrl+ S” to save the module data. After that go to the workbook and type “=wrk_book_name()” as shown in below image.
The above method call will return the active workbook name, as depicted below:
Example 2: To obtain the current workbook name in excel, by using kutool plus.
To generate active workbook name, go to the “Kutool Plus”, and choose first option “Workbook & Sheets”. After that select the first option of the appeared tab “Workbook”. This will open another drop-down list, from the appeared list select “Insert Workbook Information”.
The successful completion of the above step opens the “Insert Workbook Information” dialog box. In the appeared dialog box, under the “information” section, choose the second radio button “Workbook name”. And, at the second section “Insert At” go to the “Range” option and pass the cell name, where user wants to display the worksheet name. for this case, the chosen location is C2 cell, that is C column with 2nd row.
Consider below generated output to understand the result. Here, sample.xlsx is the name of the current workbook.
This article is based on designing a module that will allow the user to obtain the name of the current workbook. The second example will allow users to use the kutools plus tool. This tool is a software add-in for Microsoft Excel, and it allows users to provide a variety of features to ease out tasks and enhance productivity, with the latest Excel versions.
Kickstart Your Career
Get certified by completing the courseGet Started