Path to Windows Desktop


Posted by Bill on January 18, 2002 4:04 AM

How can I return the path to the Windows desktop in VBA?

Posted by Ivan F Moala on January 18, 2002 12:06 PM

Try this

Const CSIDL_DESKTOP = &H0
Const CSIDL_PROGRAMS = &H2
Const CSIDL_CONTROLS = &H3
Const CSIDL_PRINTERS = &H4
Const CSIDL_PERSONAL = &H5
Const CSIDL_FAVORITES = &H6
Const CSIDL_STARTUP = &H7
Const CSIDL_RECENT = &H8
Const CSIDL_SENDTO = &H9
Const CSIDL_BITBUCKET = &HA
Const CSIDL_STARTMENU = &HB
Const CSIDL_DESKTOPDIRECTORY = &H10
Const CSIDL_DRIVES = &H11
Const CSIDL_NETWORK = &H12
Const CSIDL_NETHOOD = &H13
Const CSIDL_FONTS = &H14
Const CSIDL_TEMPLATES = &H15
Const MAX_PATH = 260
Declare Function SHGetSpecialFolderLocation Lib "Shell32" _
(ByVal hwnd As Long, ByVal nFolder As Long, ppidl As Long) As Long

Declare Function SHGetPathFromIDList Lib "Shell32" _
(ByVal Pidl As Long, ByVal pszPath As String) As Long

Function SpecFolder(CSIDL As Long) As String
Dim DeskTopSysFile As String
Dim hwnd As Long
Dim Pidl As Long

'Get the windows desktop Pidl
SHGetSpecialFolderLocation 0, 0, Pidl

'assign spaces
DeskTopSysFile = Space(260)

'Get the path
SHGetPathFromIDList Pidl, DeskTopSysFile

'Now shorten
SpecFolder = Left(DeskTopSysFile, InStr(1, DeskTopSysFile, vbNullChar) - 1)

End Function

Sub DeskTop()

MsgBox SpecFolder(CSIDL_DESKTOP)

End Sub

Ivan

Posted by Juan Pablo G. on January 18, 2002 12:44 PM

Ivan,

Do you know if this works in Win XP ? (I don't have anywhere to test that !)

Thanks

Juan Pablo G.

Posted by Ivan F Moala on January 18, 2002 9:54 PM

Juan
I'm not sure as I don't have Xp....the APIs and
the consts I would guess would not have changed
so without testing I would say yes ?

Ivan

,



Posted by Bill on January 20, 2002 3:34 AM

Works Perfectly

Thanks Ivan,

It works great!

Bill