I partially created / recorded a macro to do the following:
- Create a temp file named vbsTest.xlsx
- Copy some data from the worksheet with the macro to vbsTest.xlxs
I get an "out of range error" when Windows("vbsTest.xlsx").Activate or Workbooks("vbsTest.xlsx").Activate is called to set focus to the temp file and copy in the necessary data.
I've searched and found nothing that resolves what is going on. *Note, both files are located in the same folder. Please help!
Sub Macro1()
'
' Macro1 Macro
'create new excel document to house post-processed Network ATC file
'create the excel object
Set objExcel = CreateObject("Excel.Application")
'view the excel program and file, set to false to hide the whole process
objExcel.Visible = True
'save the new excel file (make sure to change the location) 'xls for 2003 or earlier
Set objWorkbook = objExcel.Workbooks.Add
objWorkbook.SaveAs "H:\vbsTest.xlsx"
'begin processing input file
Range("B4").Select
Selection.ShowDetail = True
Sheets("Sheet1").Select
Range("C4").Select
Selection.ShowDetail = True
Selection.Copy
Workbooks("vbsTest.xlsx").Activate
ActiveSheet.Paste
Windows("Test doc.xlsx").Activate
Sheets("Sheet2").Select
Application.CutCopyMode = False
Selection.Copy
Workbooks("vbsTest.xlsx").Activate
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
Windows("Test doc.xlsx").Activate
End Sub