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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
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,136,341
Messages
5,675,206
Members
419,553
Latest member
hanahass

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