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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
Office Version
  1. 365
Platform
  1. Windows
Polo

How does typing the name into the Run box prove the existence of the file?
 

gut7ue

New Member
Joined
Feb 19, 2010
Messages
2
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. ;(
 

Forum statistics

Threads
1,171,832
Messages
5,877,817
Members
433,288
Latest member
Kietkiengiang

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