I am attempting to write code that will create a new workbook, and then copy a sheet from ThisWorkbook (sheet is named "PO Form") into that new workbook. I have not done this before using VBA, and have hit a roadblock.
Here's the simplified version of my code:
On the last line, I am getting Run-time error 9: subscript out of range. I searched around online, and I've seen various forums that indicate this is the proper syntax for copying a sheet to a new workbook. But obviously I am misunderstanding something. Any help would be appreciated!
Here's the simplified version of my code:
Code:
Dim NewWBname As String
Dim POwb As Workbook
NewWBname = Application.GetSaveAsFilename( _
FileFilter:="XLSX files, *.xlsx", _
Title:="Export POs as Excel file...")
Set POwb = Workbooks.Add
POwb.SaveAs NewWBname
ThisWorkbook.Activate
Sheets("PO Form").Select
Sheets("PO Form").Copy After:=Workbooks(NewWBname).Sheets(1)
On the last line, I am getting Run-time error 9: subscript out of range. I searched around online, and I've seen various forums that indicate this is the proper syntax for copying a sheet to a new workbook. But obviously I am misunderstanding something. Any help would be appreciated!