I am trying to import a sheet from one excel file into a new file.
I created the below to accomplish this saving it into "PERSONAL.XLSB"
When I execute the code, I keep getting:
Run-Time error '1004':
Copy method of Worksheet class failed
I am able to open the sourceworkbook as expected, but then I get an error on the "Copy After:" Line.
For the life of me, I can't figure out what is wrong. Any help is greatly appreciated.
I created the below to accomplish this saving it into "PERSONAL.XLSB"
When I execute the code, I keep getting:
Run-Time error '1004':
Copy method of Worksheet class failed
I am able to open the sourceworkbook as expected, but then I get an error on the "Copy After:" Line.
For the life of me, I can't figure out what is wrong. Any help is greatly appreciated.
Code:
Sub Copy_Frontlog()
Dim sourceworkbook As Workbook
Dim currentworkbook As Workbook
Set currentworkbook = thisworkbook
MyFile = Application.GetOpenFilename()
Set sourceworkbook = Workbooks.Open(MyFile)
sourceworkbook.Sheets("FrontLog").Copy After:=currentworkbook.Sheets("Sheet1")
sourceworkbook.Close
currentworkbook.Activate
Worksheets("Sheet1").Activate
Worksheets("Sheet1").Range("A1").Select
End Sub