Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Language independent way to get "My Documents" folder in VBA Excel 2003

Tags:

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?

like image 875
Diego Castro Avatar asked Oct 13 '11 08:10

Diego Castro


People also ask

How do you get a list of all files in a folder into Excel VBA?

Using the Dir() function you can get the list of files and folders in a specific path. The Dir() function takes 2 input parameters, the directory path and the type of file we are looking for: What is this? strPath is the path of the directory which the files and folder are in.


1 Answers

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.

like image 183
Fionnuala Avatar answered Oct 17 '22 06:10

Fionnuala