Windows Explorer

David Sinclair

Registered User.
Local time
Today, 11:25
Joined
Jan 2, 2006
Messages
14
Would someone provide advice on how to have Windows Explorer open in a particular folder. The code below works as long as the folder name does not have characters in the folder name, e.g. commas.

Sub OpenExplorer()
Dim strFolderName As String
strFolderName = "C:\Demo, Level1"
Shell "Explorer.exe /e, /root," & strFolderName
End Sub
 
I once had a similar problem with file names that had a comma within the file name on a server. See if you can modify the code at this thread to meet your needs for I doubt a comma in a directory name is really necessary. Renaming Network Files
 
In order to have the Explorer open with a directory path containing comma, ensure that the foldername string is stored as quoted text, beginning and ending with ". To get the example mentioned to work, write

strFolderName = """C:\Demo, Level1"""

The Shell command string

"Explorer.exe /e, /root," & strFolderName

will then be:

Explorer.exe /e, /root,"C:\Demo, Level1"

and the comma is interpreted as part of the directory
instead of a command parameter separator

Alternatively (maybe better), keep the strFolderName as it is, and build the Shell command with

"Explorer.exe /e, /root,""" & strFolderName & """
 
This is something that I have been looking at and I cannot wrap my head around this

GH solution looks very good -
but I could not get it to work 100% - so I parked this for some time - until i had a clear moment - still parked - this solution GH is visually pretty good - and is the one i prefer -

sorry i cannot shed any light on the matter-
 
Hi everyone,

I've been using google to find answers to my Access problems and its about time i gave something back.

If you have a variable with a comma in it, and you need to perform file or directory commands, you will encounter probs. Here's how i got around it - this will open up an explorer window at the location contained by the variable zPath:


Dim zPath, RetVal

zPath = "C:\temp, 1"

RetVal = Shell("Explorer.exe """ & zPath & """", vbNormalFocus)

Hope this helps!
 

Users who are viewing this thread

Back
Top Bottom