Excel XP, WinXP
I have a number of Excel files open, say One.xls, Two.xls, Three.xls. I
want to do something with each file in turn in a For loop. The "Test1"
macro has a "Type Mismatch" error in the "For" line. What is the correct
way to write this "For" line? I finally went with the Test2 macro but it
seems awkward. Thanks for your help. Otto
Sub Test1()
Dim wb As Workbook
For Each wb In Workbooks(Array("One.xls", "Two.xls", "Three.xls"))
MsgBox wb.Name
Next wb
End Sub
Sub Test2()
Dim wb As Workbook
Dim wbName As Variant
For Each wbName In Array("One.xls", "Two.xls", "Three.xls")
MsgBox Workbooks(wbName).Name
Next wbName
End Sub
Bookmarks