Import Sheet error

Panik

New Member
Joined
Nov 12, 2009
Messages
20
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.

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
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Works fine for me...
Make sure the sheet names are correct AND neither workbook is protected !!
Code:
Sub Copy_Frontlog()
Dim sourceworkbook As Workbook, 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
 
Upvote 0
hmm. None of the sheets are protected. Also tried creating new files to test with. I get the exact same error. I even tried from scratch on another computer.

Any other thoughts? Thanks for the help.
 
Upvote 0
When checking the sheet names did you make sure there were no leading / trailling spaces in the sheet name ??
 
Upvote 0
Unless you are trying to copy the sheet into you personal.xlsb file, I suspect that this
Code:
Set currentworkbook = thisworkbook
should be
Code:
Set currentworkbook = ActiveWorkbook
 
Upvote 0
Thanks Fluff!! You solved it!! I couldn't see that for the life of me! Thanks again.


Unless you are trying to copy the sheet into you personal.xlsb file, I suspect that this
Code:
Set currentworkbook = thisworkbook
should be
Code:
Set currentworkbook = ActiveWorkbook
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,150
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top