Open a file using Macro

gut7ue

New Member
Joined
Feb 19, 2010
Messages
2
Hi,

I write VBA codes every now and then and am quite comfortable with it. However, I am failing to do something very very basic and totally perplexed at what am I doing wrong.

I am trying to open a file from a code. I have written a very simple one line Sub for it, which goes like:

Sub SendTradeRequest
Workbooks.Open "C:\Users\Precision Engg Corp\Desktop\Test.xlsx"
End Sub

The workbook as above, does exist. The proof is that when I copy paste the above name in Run command under Start menu, it opens the file. But everytime I run the code from Excel, I get an error message:

-------
Run-time error '1004':

'C:\Users\Precision Engg Corp\Desktop\Test.xlsx' could not be found. Check the spelling, and verify the file location..... and all that jazz.
-------

What am I doing wrong? Can someone help please, it's driving me nuts?

Thanks,
Polo
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Polo

How does typing the name into the Run box prove the existence of the file?
 
Upvote 0
Well, when I type the name in the Run Box and hit enter, it opens the file.

To remove any confusion, I also hit Ctrl+O in Excel and pasted the complete path of the file as in Macro. When I hit enter, guess what, the file opens up.

But when I run it in the macro, surprise! surprise! the file doesn't open. ;(
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,252
Members
449,075
Latest member
staticfluids

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