Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refer To My Documents Folder 1

Status
Not open for further replies.

CWestII

Programmer
Jan 30, 2004
25
US
Hi all!

Does anyone know how to refer to the My Documents folder and other standard windows folders without having to type the full file path?

I trying to avoid referring to C:\Documents and Settings\UserName\My Documents.

The next version of Windows may not follow this path exactly and I want something generic enough that I don't have to change based on the operating system differences.

Thanks in advance for any help you may be able to provide!
 
Create a reference to

Microsoft Shell Controls and Automation

Code:
Public Sub SpecificFolders()
Debug.Print "SPECIAL FOLDERS"
Debug.Print "Recycle Bin  " & GetSpecialPath(ssfBITBUCKET)
Debug.Print "Control Panel  " & GetSpecialPath(ssfCONTROLS)
Debug.Print "My Computer  " & GetSpecialPath(ssfDRIVES)
Debug.Print "My Network Places  " & GetSpecialPath(ssfNETWORK)
Debug.Print "Printers and Faxes  " & GetSpecialPath(ssfPRINTERS)  
Debug.Print "Docs & Settings  " & GetSpecialPath(ssfPERSONAL)
End Sub

Function GetSpecialPath(vDir As ShellSpecialFolderConstants)
    With New Shell
        GetSpecialPath = .NameSpace(vDir).Self.Path
    End With
End Function
 
CWestII,
If you didn't want to use an external reference you could use [tt]Environ$("USERPROFILE")[/tt] to return the path.

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top