Private Declare Function GetSpecialFolderPath Lib "shell32.dll" _
Alias "SHGetSpecialFolderLocation" (ByVal hwndOwner As Long, _
ByVal nFolder As Long, ByRef psidl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
(ByVal pidl As Long, ByVal pszPath As String) As Long
Private Sub Command1_Click()
Dim pidl As Long
Dim strDesktopPath As String
Dim CSIDL_DESKTOP As Long
Const CSIDL_DESKTOPDIRECTORY = &H10& ' Desktop folder only for My Documents object
CSIDL_DESKTOP = CSIDL_DESKTOPDIRECTORY
If GetSpecialFolderPath(0, CSIDL_DESKTOP, pidl) = 0 Then
strDesktopPath = Space$(260)
If SHGetPathFromIDList(pidl, strDesktopPath) Then
strDesktopPath = Left$(strDesktopPath, InStr(strDesktopPath, Chr$(0)) - 1)
End If
End If
MsgBox strDesktopPath
End Sub