ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to get path for "my documents" (https://www.excelbanter.com/excel-programming/373800-how-get-path-my-documents.html)

Wang

How to get path for "my documents"
 
Dear gurus:
With environ() I can find homepath or userprofile, but how can I get the
path for "my documents"? Thanks in advance!
wang

moon[_7_]

How to get path for "my documents"
 

"Wang" schreef in bericht
...
Dear gurus:
With environ() I can find homepath or userprofile, but how can I get the
path for "my documents"? Thanks in advance!
wang



It seems the good old Windows Script Host offers help:

Dim wsh
Set wsh = CreateObject("WScript.Shell")
MsgBox wsh.SpecialFolders("MyDocuments")
Set wsh = Nothing





NickHK

How to get path for "my documents"
 
You can see all the info available from Environ with something like this:

Dim i As Long
For i = 1 To 35 'Or some suitable number
Debug.Print Environ(i)
Next

However, do not use the numeric index in production, as there is no
guarentee how each computer is organised.
Use the text instead
Environ("USERPROFILE")

Orherwise there is the API route:
http://www.mvps.org/access/api/api0054.htm

NickHK

"Wang" wrote in message
...
Dear gurus:
With environ() I can find homepath or userprofile, but how can I get the
path for "my documents"? Thanks in advance!
wang




Wang

How to get path for "my documents"
 
It works fine. Thank you, Moon!

"moon" wrote:


"Wang" schreef in bericht
...
Dear gurus:
With environ() I can find homepath or userprofile, but how can I get the
path for "my documents"? Thanks in advance!
wang



It seems the good old Windows Script Host offers help:

Dim wsh
Set wsh = CreateObject("WScript.Shell")
MsgBox wsh.SpecialFolders("MyDocuments")
Set wsh = Nothing






Wang

How to get path for "my documents"
 
I've used this loop to print out all the environment variables and have not
found entry for "mydocuments". The API is quite unfamiliar to me (I've never
worked with it). But the mothod Moon told me (see his reply) has solved my
question. API might be a topic for my future study. Thank you for your reply!
wang

"NickHK" wrote:

You can see all the info available from Environ with something like this:

Dim i As Long
For i = 1 To 35 'Or some suitable number
Debug.Print Environ(i)
Next

However, do not use the numeric index in production, as there is no
guarentee how each computer is organised.
Use the text instead
Environ("USERPROFILE")

Orherwise there is the API route:
http://www.mvps.org/access/api/api0054.htm

NickHK

"Wang" wrote in message
...
Dear gurus:
With environ() I can find homepath or userprofile, but how can I get the
path for "my documents"? Thanks in advance!
wang





NickHK

How to get path for "my documents"
 
But you have
Environ("USERPROFILE") & "\My Documents"

Not sure if this is valid an non-English systems, although the API will
always work.

NickHK

"Wang" wrote in message
...
I've used this loop to print out all the environment variables and have

not
found entry for "mydocuments". The API is quite unfamiliar to me (I've

never
worked with it). But the mothod Moon told me (see his reply) has solved my
question. API might be a topic for my future study. Thank you for your

reply!
wang

"NickHK" wrote:

You can see all the info available from Environ with something like

this:

Dim i As Long
For i = 1 To 35 'Or some suitable number
Debug.Print Environ(i)
Next

However, do not use the numeric index in production, as there is no
guarentee how each computer is organised.
Use the text instead
Environ("USERPROFILE")

Orherwise there is the API route:
http://www.mvps.org/access/api/api0054.htm

NickHK

"Wang" wrote in message
...
Dear gurus:
With environ() I can find homepath or userprofile, but how can I get

the
path for "my documents"? Thanks in advance!
wang







Wang

How to get path for "my documents"
 
That's the point! The German version has "\Eigene Dateien" instead of "\My
Documents".

"NickHK" wrote:

But you have
Environ("USERPROFILE") & "\My Documents"

Not sure if this is valid an non-English systems, although the API will
always work.

NickHK

"Wang" wrote in message
...
I've used this loop to print out all the environment variables and have

not
found entry for "mydocuments". The API is quite unfamiliar to me (I've

never
worked with it). But the mothod Moon told me (see his reply) has solved my
question. API might be a topic for my future study. Thank you for your

reply!
wang

"NickHK" wrote:

You can see all the info available from Environ with something like

this:

Dim i As Long
For i = 1 To 35 'Or some suitable number
Debug.Print Environ(i)
Next

However, do not use the numeric index in production, as there is no
guarentee how each computer is organised.
Use the text instead
Environ("USERPROFILE")

Orherwise there is the API route:
http://www.mvps.org/access/api/api0054.htm

NickHK

"Wang" wrote in message
...
Dear gurus:
With environ() I can find homepath or userprofile, but how can I get

the
path for "my documents"? Thanks in advance!
wang







NickHK[_3_]

How to get path for "my documents"
 
Use the API route in the link then, with
Public Const CSIDL_PERSONAL = &H5

NickHK

"Wang" ...
That's the point! The German version has "\Eigene Dateien" instead of "\My
Documents".

"NickHK" wrote:

But you have
Environ("USERPROFILE") & "\My Documents"

Not sure if this is valid an non-English systems, although the API will
always work.

NickHK

"Wang" wrote in message
...
I've used this loop to print out all the environment variables and have

not
found entry for "mydocuments". The API is quite unfamiliar to me (I've

never
worked with it). But the mothod Moon told me (see his reply) has solved
my
question. API might be a topic for my future study. Thank you for your

reply!
wang

"NickHK" wrote:

You can see all the info available from Environ with something like

this:

Dim i As Long
For i = 1 To 35 'Or some suitable number
Debug.Print Environ(i)
Next

However, do not use the numeric index in production, as there is no
guarentee how each computer is organised.
Use the text instead
Environ("USERPROFILE")

Orherwise there is the API route:
http://www.mvps.org/access/api/api0054.htm

NickHK

"Wang" wrote in message
...
Dear gurus:
With environ() I can find homepath or userprofile, but how can I
get

the
path for "my documents"? Thanks in advance!
wang










All times are GMT +1. The time now is 03:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com