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.

Step 1:

Consider the below provided excel worksheet to understand the process to obtain the name of current workbook in excel by using the VBA code.

Step 2:

To open the VBA editor, click on the “Developer” tab, and then under the code section, choose “Visual Basic” code. As, depicted below:

Step 3:

This will open the “Microsoft Visual Basic Application” dialog box, as shown below

Step 4:

Go to the “Insert” tab and then click on “Module”.

Step 5:

This will open the below provided code area:

Step 6:

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

Step 7:

Press “ctrl+ S” to save the module data. After that go to the workbook and type “=wrk_book_name()” as shown in below image.

Step 8:

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.

Step 1:

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”.

Step 2:

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.

Step 3:

Consider below generated output to understand the result. Here, sample.xlsx is the name of the current workbook.

Conclusion:

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.

Updated on: 17-Apr-2023

261 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements