Thread: Workbooks Array
View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Workbooks Array

I see that I can't set up an array of workbooks

You can set up an array of workbooks:

Sub test()

Dim i As Long
Dim arrWBs(1 To 2) As Workbook

Set arrWBs(1) = Workbooks("Book1")
Set arrWBs(2) = Workbooks("Book2")

For i = 1 To 2
MsgBox arrWBs(i).Name
Next

End Sub

Note that if the workbook hasn' t been saved yet you leave
the extension off, but if the workbook was saved then you add the .xla or
..xla.


RBS

"Otto Moehrbach" wrote in message
...
Thanks guys. I see that I can't set up an array of workbooks so I went
with the array of workbook names. I just thought there was a better way.
Thanks again. Otto
"Otto Moehrbach" wrote in message
...
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