Opening a subfolder of %MyDocuments% using Shell explorer.exe

C

CES

All,
I was hoping that someone might be able to help me with a problem I am having opening Windows Explorer from a forms element.

The following code works fine:

Shell "explorer.exe / e, ""%MyDocuments%\"", vbNormalFocus"

However when I try to access a subdirectory of %MyDocuments% using the following, Windows Explorer just opens the root directory of my documents and ignores a subdirectory request.

Shell "explorer.exe / e, ""%MyDocuments%\SomeFolder"", vbNormalFocus"

Additionally when Explorer opens under either of the above it opens minimized to the taskbar(I'm using Windows Vista and Office 2007).

if anyone has a clue as to how to correct either of these problems I would be grateful. Thanks in advance. - CES
 
A

Allen Browne

Open a command prompt, and enter:
SET
You will see a list of environment variables.
Use a name such as homepath.

You can open explorer to the specific folder using the /select switch, e.g.:
%SystemRoot%\explorer.exe /e, /select,"%homepath%\Documents"

Or you could just ShellExecute to open the default file manager like this:
http://www.mvps.org/access/api/api0018.htm
 
W

Wei Lu [MSFT]

Hello CES,

This issue is because Vista has changed the behavior of the explorer when
you did not specify a right folder path.

In previous OS, when you did not specify a correct folder path, explorer
will give a error message to let you know. But in vista, explorer will only
redirect you to the My Documents.

According to your description, I assume that you did not add the
environment variable "%MyDocuments%" in your computer because it is not a
default environment variable.

You need to add this variable in your computer and direct to your own
document.

Or, you could use the %UserProfile%\Documents\ to direct to the documents
folder.

Hope this will be helpful!

Sincerely,

Wei Lu

Microsoft Online Community Support

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
D

Douglas J. Steele

I didn't think Access was capable of resolving references to environment
variables using % notation.

I thought you needed to use the Environ function to get at the values of the
variables, something like:

Shell """" & Environ("SystemRoot") & "\explorer.exe"" /e, /select,""" &
Environ("homepath" & "\Documents"""
 
A

Allen Browne

Doug, you are right for the first environment variable, which must be
resolved to get the path to the executable.

The 2nd one explorer can resolve, so you can get away with:
Shell( Environ("SystemRoot") & "\explorer.exe /e,
/select,""%homepath%\Documents""")
 
C

CES

Allen said:
Doug, you are right for the first environment variable, which must be
resolved to get the path to the executable.

The 2nd one explorer can resolve, so you can get away with:
Shell( Environ("SystemRoot") & "\explorer.exe /e,
/select,""%homepath%\Documents""")
Allen,
Unfortunately Using %homepath%\Documents assumes that the "My Documents" folder resides under C:\Users\UserName\Documents, in my case %MyDocuments% points to a different partition\folder "d:\Data Files\UserFiles\User Name" so unfortunately I'm left with my initial problem. Unfortanatly I can't hard code in the path becouse diferent users have diferant pathes.

Also when I looked at the environment variables that are available using SET "My Documents" or "Documents" were not listed. - CES

Another issue related to to this is

Shell "explorer.exe /e /select, """"", 1 - Will resolve to Computer(My Computer) which lists all of my hard drives. I'm assuming this is normal behavior.

However

Shell "explorer.exe /e /select, ""xxx ANYTEXT xxx""" - will always resolve to the my documents folder.

- CES
 
A

Allen Browne

Okay: perhaps you could ask in a Windows group if someone knows the
environment variable name for the user's Documents folder.
 

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