looking for help with syntax error

P

Paul

I'm trying to write code to open Windows Explorer to a designated folder.
The code I've got so far opens Win Explorer as long as the directory path is
hard-wired in the code such as:

ShellID = Shell("Explorer.exe M:\Apps", vbNormalFocus)

But when I try to use a variable to designate the path, such as

strPath = "M:\Apps"
ShellID = Shell("Explorer.exe strPath", vbNormalFocus),

I get an error message saying

The path 'strPath' does not exist or is not a directory.

Since the code opens Windows Explorer just fine when the directory path is
hard wired without using the variable strPath, the problem is with my
syntax.

What change can I make to the syntax I'm using so that the code will open
Win Explorer when I use a variable for the directory path?

Thanks in advance,

Paul
 
D

Douglas J. Steele

strPath = "M:\Apps"
ShellID = Shell("Explorer.exe " & strPath, vbNormalFocus)

If there's a chance that strPath will contain a space in it ("C:\Program
Files"), use

ShellID = Shell("Explorer.exe """ & strPath & """", vbNormalFocus)

(that's three double quotes in a row before, and four double quotes in a row
after)
 
P

Paul

Works great. Thanks much, Doug. And thanks for the two alternatives.

A last question:

The command opens Win Ex in single pane view. Is there way to modify

ShellID = Shell("Explorer.exe " & strPath, vbNormalFocus)

so that it will open in double-pane view with the directory tree on the
left?

Paul
 
D

Dirk Goldgar

Paul said:
Works great. Thanks much, Doug. And thanks for the two alternatives.

A last question:

The command opens Win Ex in single pane view. Is there way to modify

ShellID = Shell("Explorer.exe " & strPath, vbNormalFocus)

so that it will open in double-pane view with the directory tree on the
left?


Hmm, for me it opens in Explorer view, which I think is what you're looking
for. But you could try specifying the /e command-line switch:

ShellID = Shell("Explorer.exe /e " & strPath, vbNormalFocus)

Here's a somewhat dated article on exporer's command-line switches:

http://support.microsoft.com/kb/130510
 
P

Paul

Doug,

I tried using the /e switch by entering

ShellID = Shell("Explorer.exe /e " & strPath, vbNormalFocus)

but I get an error message saying

The path '/e M:\Apps' does not exist or is not a directory.

I tried as many variations as I could think of in the above Shell command to
get it to work, but to no avail. It works without without the /e, but it
only opens in single-paned My Computer view. You were right - I'm trying to
open in the two-paned Windows Explorer view.

Is there any way I can modify the syntax in the Shell expression above so it
will accept the /e switch and open in Windows Explorer view?

Thanks

Paul
 
P

Paul

I found an answer to my last question when I checked the reply I had
received from Stuart McCall back in March to a related question I had asked
in this newsgroup. It's a matter of inserting a comma after the /e switch:

ShellID = Shell("Explorer.exe /e," & strPath, vbNormalFocus)

My thanks again to Doug, Dirk and Stuart for your suggestions and help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top