By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,482 Members | 2,411 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,482 IT Pros & Developers. It's quick & easy.

Open File using Variable Path?

P: n/a
I'm trying to open a file from VBA using a variable path and am not
having very much luck. Can anyone help?

This works:
retval = Shell("""Excel.EXE"" ""C:\Program files\MyPath\MyFile.xls""",
1)

This does not like the space in 'Program Files':
retval = Shell("Excel.EXE " & Application.CurrentProject.Path &
"\MyFile.xls", 1)

I've tried quotation marks all over the place in all sorts of
combinations and cannot get it to work. With the above example I get
the following message:

'C:\Program.xls' could not be found...

That one is immediately followed by:

'Files\MyPath\MyFile.xls' could not be found.

Thanks in advance for any suggestions.

Aug 23 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You've got the pairs of double quotes missing, try

retval = Shell("Excel.EXE """ & Application.CurrentProject.Path &
"\MyFile.xls""", 1)
--

Terry Kreft
"Jason Gyetko" <ja**********@epower-inc.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
I'm trying to open a file from VBA using a variable path and am not
having very much luck. Can anyone help?

This works:
retval = Shell("""Excel.EXE"" ""C:\Program files\MyPath\MyFile.xls""",
1)

This does not like the space in 'Program Files':
retval = Shell("Excel.EXE " & Application.CurrentProject.Path &
"\MyFile.xls", 1)

I've tried quotation marks all over the place in all sorts of
combinations and cannot get it to work. With the above example I get
the following message:

'C:\Program.xls' could not be found...

That one is immediately followed by:

'Files\MyPath\MyFile.xls' could not be found.

Thanks in advance for any suggestions.

Aug 23 '06 #2

P: n/a
Thanks, that worked. Not sure why it was so difficult, seemed like I
tried quotes in every possible combination.

Terry Kreft wrote:
You've got the pairs of double quotes missing, try

retval = Shell("Excel.EXE """ & Application.CurrentProject.Path &
"\MyFile.xls""", 1)
--

Terry Kreft
"Jason Gyetko" <ja**********@epower-inc.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
I'm trying to open a file from VBA using a variable path and am not
having very much luck. Can anyone help?

This works:
retval = Shell("""Excel.EXE"" ""C:\Program files\MyPath\MyFile.xls""",
1)

This does not like the space in 'Program Files':
retval = Shell("Excel.EXE " & Application.CurrentProject.Path &
"\MyFile.xls", 1)

I've tried quotation marks all over the place in all sorts of
combinations and cannot get it to work. With the above example I get
the following message:

'C:\Program.xls' could not be found...

That one is immediately followed by:

'Files\MyPath\MyFile.xls' could not be found.

Thanks in advance for any suggestions.
Aug 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.