VBA Get Workbook Name in Excel. We can return workbook name usingWorkbook.Name property. Here workbook represents object. It is part of Workbooks collection. It 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 Name of the Workbook in Excel VBA.
Where expression: It represents Workbook object which is part of workbooks collection.
Name: It represents property of Workbook object.
Let us see the following example macro to get name of the active workbook in Excel VBA.
'VBA Get Name of the Active Workbook in Excel Sub VBA_Get_ActiveWorkbook_Name() 'Variable declaration Dim sActiveWorkbookName As String sActiveWorkbookName = ActiveWorkbook.Name End Sub
Please find the output screenshot of the above macro code.
Let us see the following example macro to get name of the current workbook in Excel VBA.
'VBA Get Name of the Current Workbook in Excel Sub VBA_Get_CurrentWorkbook_Name() 'Variable declaration Dim sCurrentWorkbookName As String sCurrentWorkbookName = ThisWorkbook.Name End Sub
Here is the output screenshot of the above macro code.
Let us see the instructions to use above macro procedure in Visual basic editor.
- Save Visual Basic Editor(VBE) by clicking Alt +F11
- Go to code window by clicking F7
- Copy above specified macro or procedure
- Paste above copied code in code window
- Run macro by clicking F5 or Run command
- You can see output on the screen
- Find above output screenshot of the specified procedure.
You may also like the related Workbook Object articles.