I
ian123
I have been using the following code to combine sheets from workbook
saved in a folder called "MyData" andit has been working fine.
However today i am being told that "Method 'Copy' of object 'Sheets
failed" and the lines
wkbk.Worksheets.Copy After:=ThisWorkbook. _
Worksheets(ThisWorkbook.Worksheets.Count)
are highlighted as the problem. I can't figure out whats going on an
how to fix it. Can anyone help please (I have included the complet
code below...)
Sub GetSheets()
Dim sPath As String, i As Long
Dim varr As Variant
Dim wkbk As Workbook
sPath = "C:\MyData\"
varr = Array("Data1.xls", "Data2.xls", "Data3.xls")
For i = LBound(varr) To UBound(varr)
Set wkbk = Workbooks.Open(sPath & varr(i))
wkbk.Worksheets.Copy After:=ThisWorkbook. _
Worksheets(ThisWorkbook.Worksheets.Count)
wkbk.Close SaveChanges:=False
Next
End Su
saved in a folder called "MyData" andit has been working fine.
However today i am being told that "Method 'Copy' of object 'Sheets
failed" and the lines
wkbk.Worksheets.Copy After:=ThisWorkbook. _
Worksheets(ThisWorkbook.Worksheets.Count)
are highlighted as the problem. I can't figure out whats going on an
how to fix it. Can anyone help please (I have included the complet
code below...)
Sub GetSheets()
Dim sPath As String, i As Long
Dim varr As Variant
Dim wkbk As Workbook
sPath = "C:\MyData\"
varr = Array("Data1.xls", "Data2.xls", "Data3.xls")
For i = LBound(varr) To UBound(varr)
Set wkbk = Workbooks.Open(sPath & varr(i))
wkbk.Worksheets.Copy After:=ThisWorkbook. _
Worksheets(ThisWorkbook.Worksheets.Count)
wkbk.Close SaveChanges:=False
Next
End Su