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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,219,162
Messages
6,146,659
Members
450,706
Latest member
LGVBPP

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