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.
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.
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.
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.
You can refer the following link for the step by step instructions to execute VBA code or procedure.
Click on the following links of the useful resources. These helps to learn and gain more knowledge.