How to Loop through all open Workbboks
Hi,
I'm trying to loop through all open workbooks excluding the one I'm working in as the master workbook and want to copy the first two cells (A1:A2) in each workbook in each sheet, back to the workbook that I'm working in.
Here is the code I have so far, but I keep getting a runtime error '438':
Sub Macro1()
'
' Macro1 Macro
'
Dim wb As Workbook
Dim ws As Worksheet
Dim myrange As Range
Dim i As Long
For Each wb In Application.Workbooks
If wb.Name <> "Book1.xlsx" Then
For Each ws In wb.Sheets()
For i = 3 To i + 2
ws.Range("A1:A2").Copy Destination:=Windows("Book1").Sheets("Sheet1").Ran ge(Cells(i, 1), Cells((i + 1), 1)).String
Next i
Next ws
End If
Next wb
End Sub
|