How to get the "My documents" absolute path?

  • Thread starter Thread starter Anonimo
  • Start date Start date
A

Anonimo

Depending on the user the My Documents Path changes, how to kow the current
My document Path or can I write someting like %My documents% ...

Thanks a lot
 
I normally use Application.DefaultFilePath

It's often "My Documents" and if it's not, at least it's where the user
saves her workbooks by default
 
Depending on the user the My Documents Path changes, how to kow the current
My document Path or can I write someting like %My documents% ...

In NT-based systems (2000, XP, 2003, maybe NT 4) you can use this:
Environ("USERPROFILE") & "\My Documents"

In 9x systems, it's usually on the root directory of the same drive as
the Windows directory, so you can use this to get it:
Left(Environ("WINDIR"),1) & "\My Documents"

Failing that, you can dig it out of the registry. It's located in:
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
Get the value called "Personal".
 
Just in case you really had to find "my documents":

You can use something like this to get the "\my documents" path. But it
wouldn't work well for me. I changed my default location
(tools|Options|general|Default file location).


Option Explicit
Sub testme03()

Dim wsh As Object
Dim myPath As String

Set wsh = CreateObject("WScript.Shell")
myPath = wsh.SpecialFolders.Item("mydocuments")

MsgBox myPath

End Sub

Or even:

Dim myPath As String
myPath = CreateObject("WScript.Shell").SpecialFolders.Item("mydocuments")



(but I'm betting that you want: Application.DefaultFilePath
just like Steve suggested.)
 

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

Back
Top