Thread: Workbooks Array
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Alan Beban[_2_] Alan Beban[_2_] is offline
external usenet poster
 
Posts: 783
Default Workbooks Array

Otto Moehrbach wrote:
Excel XP & Win XP
I want to work with a group of workbooks, one at a time. I wanted to use
the following statement but I get a "Type Mismatch" error on the "For
Each..." line. All the workbooks are open.
My code, simplified, is:
Dim wbOther as Workbook
For Each wbOther In Workbooks(Array("One.xls", "Two.xls", "Three.xls"))
MsgBox wbOther.Name
Next wbOther
How can I setup a "For" loop for a group of workbooks?
Thanks for your time. Otto


The following works:

Sub test12()
Dim x, y As Byte
x = Array("One.xls", "Two.xls", "Three.xls")
For y = LBound(x) To UBound(x)
Debug.Print Workbooks(x(y)).Name
Next y
End Sub

Alan Beban