Thursday, January 23, 2025
No menu items!
HomeData Analytics and VisualizationVBA : How to List All Open Workbooks.

VBA : How to List All Open Workbooks.

This tutorial explains how to get all the open Excel workbooks using VBA code.

Let’s take an example to understand the procedure.

There are three open workbooks which are as follows :

  1. Customer.xlsx
  2. Product.xlsx
  3. Transaction.xlsx

Task : To list the names corresponding to each workbook in a single column.

Sub listWorkbooks()
    Dim i As Long
    Dim WorkbookNames() As String
    
    
    ReDim WorkbookNames(1 To Workbooks.Count)
    
    
    For i = 1 To Workbooks.Count
        WorkbookNames(i) = Workbooks(i).Name
        ActiveSheet.Cells(i, 1).Value = WorkbookNames(i)
    Next i
End Sub

Press Run or F5 to run the above code.

The result looks like this

VBA : List All Open Workbooks
Explanation :
  1. .Name : It returns the name of an object.
  2. .Value : It returns the value stored in the object.
  3. .Count : It returns the total count of the objects.
How ReDim works?

It alters the size of an array. WorkbookNames stores the names of workbooks from i=1 to i= Workbooks.Count

Read MoreListenData

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments