L
LetMeDoIt
Greetings,
I'm created a new Excel file on the fly and copying a specific
worksheet into that new file. This part is fine, until I try to close
that new file (see last file of code) and get the error msg:
Run time error 9
subscript out of range.
Here's the logic in the code:
newFname = "NewEXCELfile.XLS"
Set NewWks = Workbooks.Add(1).Worksheets(1)
With NewWks
.Parent.SaveAs FileName:=newFname, FileFormat:=xlWorkbookNormal
End With
NewWks.Name = "MyNewSheet"
Set destrange = NewWks.Range("A1:z100")
Set sourceRange = ThisWorkbook.Sheets("SHEET1").Range("A1:z100")
sourceRange.Copy
destrange.PasteSpecial xlPasteColumnWidths, , False, False
destrange.PasteSpecial xlPasteFormats, , False, False
destrange.PasteSpecial (xlPasteFormulas)
application.CutCopyMode = False
Workbooks(newFname).Close
Many thanks...
I'm created a new Excel file on the fly and copying a specific
worksheet into that new file. This part is fine, until I try to close
that new file (see last file of code) and get the error msg:
Run time error 9
subscript out of range.
Here's the logic in the code:
newFname = "NewEXCELfile.XLS"
Set NewWks = Workbooks.Add(1).Worksheets(1)
With NewWks
.Parent.SaveAs FileName:=newFname, FileFormat:=xlWorkbookNormal
End With
NewWks.Name = "MyNewSheet"
Set destrange = NewWks.Range("A1:z100")
Set sourceRange = ThisWorkbook.Sheets("SHEET1").Range("A1:z100")
sourceRange.Copy
destrange.PasteSpecial xlPasteColumnWidths, , False, False
destrange.PasteSpecial xlPasteFormats, , False, False
destrange.PasteSpecial (xlPasteFormulas)
application.CutCopyMode = False
Workbooks(newFname).Close
Many thanks...