PDA

View Full Version : [SOLVED:] VBA Loop Through all open Workbooks



JW1990
08-24-2016, 07:49 AM
Hello all,

I have some code:
Sub Macro2()
'
' Macro2 Macro
'
'
Windows("DH.xlsx").Activate
Sheets(1).Select
Sheets(1).Copy After:=Workbooks("Data Summary.xlsm").Sheets(2)
End Sub


which I want to insert into a loop that will look through all open workbooks and perform the above. I'm hoping to get this to ignore the "Data Summary" workbook. However, the name of the files will not be known nor will the names of the sheets contained within them.

Any help is appreciated.
Thanks
JW1990

mikerickson
08-24-2016, 08:11 AM
Something like


Dim oneWorkBook as Workbook

For Each oneWorkbook in Application.Workbooks
If oneWorkbook.Name <> "Data Summary.xlsm" Then
oneWorkbook.Sheets(1).Copy After:= Workbooks("Data Summary.xlsm").Sheets(2)
End If
Next oneWorkbook

JW1990
08-24-2016, 08:22 AM
Man that was so simple and worked like a charm!

Cheers