VBA List all Open Workbooks in Excel

VBA List all Open Workbooks in Excel. It helps to know all open workbooks name. It is easy to handle and shift between workbooks. We have an option to open multiple workbooks in MS Office Excel. Let us see in the following tutorial how to list open Workbooks in Excel VBA.

Syntax to List all Workbooks in Excel VBA

Here is the following syntax to List all Open Workbooks in Excel VBA.

For Each Workbook in Application.Workbooks
      Statements...
Next

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

Macro to List all Workbooks in Excel VBA

Let us see the following example macro to List all Open Workbooks in Excel VBA

'VBA List Open Workbooks in Excel
Sub VBA_List_All_Open_Workbooks()
    
    'Variable declaration
    Dim xWorkbook As Workbook
    Dim sWorkbookName As String
    Dim iCount As Integer
    
    'Intialise value to a variable
    iCount = 2
    
    Sheets("WB_Names").Range("A1") = "Names of Available Workbooks"
    
    'Loop through all workbooks
    For Each xWorkbook In Application.Workbooks
        Sheets("WB_Names").Range("A" & iCount) = xWorkbook.Name & vbCrLf
        
        'Increase value
        iCount = iCount + 1
    Next

End Sub

Instructions to use Macro

Here are 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 Comment

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