Code:Option Explicit Private Declare Function SHGetSpecialFolderPath Lib "shell32.dll" Alias _ "SHGetSpecialFolderPathA" _ (ByVal hwnd As Long, _ ByVal pszPath As String, _ ByVal csidl As Long, _ ByVal fCreate As Long) As Long Private Const CSIDL_DESKTOP = &H0 Private Const MAX_PATH = 260 Private Function GetDesktopFolderPath() As String Dim sDesktopPath As String sDesktopPath = Space$(MAX_PATH) SHGetSpecialFolderPath Me.hwnd, sDesktopPath, CSIDL_DESKTOP, False GetDesktopFolderPath = Left$(sDesktopPath, InStr(sDesktopPath, vbNullChar) - 1) End Function Private Sub Command1_Click() Dim strDesktop As String strDesktop = GetDesktopFolderPath MsgBox strDesktop End Sub




Reply With Quote