Runtime error 1004 help

davejago

Board Regular
Joined
Apr 29, 2005
Messages
133
I am a beginner to macros and looking for help with a Runtime 1004 error I am getting. I have inherited a macro that does not appear to be working.

The macro should run so that when a button is pressed, excel goes and opens another workbook and copies some data over. However, I get the error that it cannot find the workbook. The macro file and the file I need to copy data from are in the same folder.

The macro is broken at the following line:

Sub Run_It()

'Copy1
Workbooks.Open (MyFileName) *THIS LINE IS BROKEN*
Windows(MyFileName).Activate
Sheets(SheetName).Select

(MyFileName) corresponds exactly to the file I need it to open, so that does not appear to be the problem. Both the macro file and the file I need to copy data from are in the same folder. I also tried to have the source file open at the same time, and it still does not work

Any thoughts?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try adding these 2 lines before the workbook.open command line:


ChDrive Thisworkbook.Path
ChDir Thisworkbook.Path
 
Upvote 0
You say that MyFileName corresponds to the file but I don't actually see it getting a value anywhere.:eek:

Also when referring to a workbook using Windows you wouldn't use the path and the filename, just the filename.
 
Upvote 0

Forum statistics

Threads
1,214,319
Messages
6,118,881
Members
448,855
Latest member
joshpep96

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