Z
z00h
Can you please help?
I've created following macro
------------------------------------------------
Public Function TEST()
Dim XLSApp As Excel.Application
Dim XLSBook1, XLSBook2 As Workbook
Set XLSBook1 = ActiveWorkbook
Set XLSApp = New Excel.Application
XLSApp.Visible = True
Set XLSBook2 = XLSApp.Workbooks.Add
XLSBook2.SaveAs "C:\TEST_1.xls"
XLSApp.Quit
XLSBook1.Worksheets("Sheet1").Copy _
after:=Workbooks("C:\TEST_1.xls").Worksheets("Sheet1")
End Function
------------------------------------------------
In general I wanted to copy Sheet1 form ActiveWorkbook to the Workbook
created and saved under "C:\TEST_1.xls" by this macro.
The only and biggest problem I get is with the
XLSBook1.Worksheets("Sheet1").Copy _
after:=Workbooks("C:\TEST_1.xls").Worksheets("Sheet1")
It always returns "Run Time Error '9' Subscript out of range".
What might be the reason for it?
TIA
I've created following macro
------------------------------------------------
Public Function TEST()
Dim XLSApp As Excel.Application
Dim XLSBook1, XLSBook2 As Workbook
Set XLSBook1 = ActiveWorkbook
Set XLSApp = New Excel.Application
XLSApp.Visible = True
Set XLSBook2 = XLSApp.Workbooks.Add
XLSBook2.SaveAs "C:\TEST_1.xls"
XLSApp.Quit
XLSBook1.Worksheets("Sheet1").Copy _
after:=Workbooks("C:\TEST_1.xls").Worksheets("Sheet1")
End Function
------------------------------------------------
In general I wanted to copy Sheet1 form ActiveWorkbook to the Workbook
created and saved under "C:\TEST_1.xls" by this macro.
The only and biggest problem I get is with the
XLSBook1.Worksheets("Sheet1").Copy _
after:=Workbooks("C:\TEST_1.xls").Worksheets("Sheet1")
It always returns "Run Time Error '9' Subscript out of range".
What might be the reason for it?
TIA