Gasman
Enthusiastic Amateur
- Local time
- Today, 00:28
- Joined
- Sep 21, 2011
- Messages
- 16,657
Hi all,
I found a piece of code that I *thought* would allow me to get the path of special folders.
Fine I thought, I can tailor that, and even use it to choose which folder I am interested in.?
So I was going to create some code and use the Select Case statement to return the required path.
Then I realised I could just use the name of the folder and created
however if I use ? getspecialfolderpath("mydocuments") in the debug window, I get
C:\Users\Public\Desktop
and not
C:\Users\Paul\Documents
I found a piece of code that I *thought* would allow me to get the path of special folders.
Code:
Function GetSpecialFolderNames()
Dim objFolders As Object
Set objFolders = CreateObject(“WScript.Shell”).SpecialFolders
MsgBox objFolders(“desktop”)
MsgBox objFolders(“allusersdesktop”)
MsgBox objFolders(“sendto”)
MsgBox objFolders(“startmenu”)
MsgBox objFolders(“recent”)
MsgBox objFolders(“favorites”)
MsgBox objFolders(“mydocuments”)
End Function
Fine I thought, I can tailor that, and even use it to choose which folder I am interested in.?
So I was going to create some code and use the Select Case statement to return the required path.
Then I realised I could just use the name of the folder and created
Code:
Function GetSpecialFolderPath(pstrFolderRequired As String) As String
Dim objFolders As Object
Dim strFolderPath As String
Set objFolders = CreateObject("WScript.Shell").SpecialFolders
strFolderPath = objFolders(pstrFolderRequired)
'Debug.Print objFolders("desktop")
'Debug.Print objFolders("allusersdesktop")
'Debug.Print objFolders("sendto")
'Debug.Print objFolders("startmenu")
'Debug.Print objFolders("recent")
'Debug.Print objFolders("favorites")
'Debug.Print objFolders("mydocuments")
Debug.Print strFolderPath
GetSpecialFolderPath = strFolderPath
Set objFolders = Nothing
however if I use ? getspecialfolderpath("mydocuments") in the debug window, I get
C:\Users\Public\Desktop
and not
C:\Users\Paul\Documents