21

I need a Language independent way to get "My Documents" folder in VBA Excel 2003.

What I have:

Public Function MyDocsPath() As String
    MyDocsPath = Environ$("USERPROFILE") & "\My Documents\"
End Function

Because the program will be used in at least 2 lang MS Windows, and the "My Documents" name changes for each language.

Is there a way, or should I try to figure out the system lang and become specific?

Diego Castro
  • 3,458
  • 4
  • 35
  • 42

2 Answers2

41

This may suit:

Set WshShell = CreateObject("WScript.Shell")
strDocuments = WshShell.SpecialFolders("MyDocuments")

From: http://msdn.microsoft.com/en-us/library/0ea7b5xe.aspx

Although the special folder name is MyDocuments, it refers to the documents folder for several versions of Windows.

Fionnuala
  • 90,370
  • 7
  • 114
  • 152
1

You may use "Documents", as the localized versions point to the same location.

' Application.PathSeparator can be used, but this
' is unlikely to work on non-Windows environments
MyDocsPath = Environ$("USERPROFILE") & "\Documents\"

(Seeing that this is a 10 years old question it may not have been the case back then. :)

berdosi
  • 61
  • 5