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?
 

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Big Monkey

Active Member
Joined
Nov 5, 2005
Messages
255
Try adding these 2 lines before the workbook.open command line:


ChDrive Thisworkbook.Path
ChDir Thisworkbook.Path
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,256
Messages
5,600,556
Members
414,388
Latest member
Pkmep4

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
Top