VBA Get Workbook Name in Excel. We can return workbook name using Workbook.Name property. Here workbook represents an object. It is part of Workbooks collection. Returns a string value representing Workbook name. We can find Active Workbook or Current Workbook name using Name property of Workbook.
Syntax to get current Workbook name using VBA in Excel
Here is the following syntax to get the Name of the Workbook using VBA in Excel.
Where expression: It represents Workbook object which is part of workbooks collection.
Name: It represents property of Workbook object to get Workbook name.
Get Name of the Active Workbook using VBA in Excel
Let us see the following example macro to get current or active workbook name in using VBA in Excel. Where ‘Name’ represents the property of Workbook object. It helps to get the name of the Workbook.
'Get Active Workbook name in Excel using VBA Sub VBA_Get_ActiveWorkbook_Name() 'Variable declaration Dim sActiveWorkbookName As String sActiveWorkbookName = ActiveWorkbook.Name End Sub
Output: Please find the output screenshot of the above macro code.
Macro to Get Current Workbook Name using VBA in Excel
Here is another example macro code to get current workbook name using VBA in Excel.
'Get current workbook name of the Workbook using VBA in Excel Sub VBA_Get_CurrentWorkbook_Name() 'Variable declaration Dim sCurrentWorkbookName As String sCurrentWorkbookName = ThisWorkbook.Name End Sub
Output: Here is the output screenshot of the above macro code.
Instructions to Run VBA Macro Code or Procedure:
You can refer the following link for the step by step instructions to execute VBA code or procedure.
Instructions to run VBA Macro Code
Other Useful Resources:
Click on the following links of the useful resources. These helps to learn and gain more knowledge.
VBA Tutorial VBA Functions List VBA Arrays in Excel Blog
VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers