VBA Get Workbook Name in Excel

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.

Syntax to return Name of the Workbook in Excel VBA

Here is the following syntax to get Name of the Workbook in Excel VBA.

expression.Name

Where expression: It represents Workbook object which is part of workbooks collection.
Name: It represents property of Workbook object.

Macro to Get Name of the Active Workbook in Excel VBA

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.

Active Workbook Name

Macro to Get Name of the Current Workbook in Excel VBA

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.

This Workbook Name

Instructions to use Macro

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.

Related Workbook Object articles

You may also like the related Workbook Object articles.

VBA Workbook Object

Leave a Reply

Your email address will not be published. Required fields are marked *