how to save file to Desktop?
hi,
i like to export a file to .xls that located in Desktop
but if the UserName or WindowLogin or ComputerName(not sure which one is the correct ;)) change the the path will also changed
ex : "C:\Documents and Settings\eRiCk\Desktop"
"C:\Documents and Settings\Vaio\Desktop"
how to solve this?
thanks
Re: how to save file to Desktop?
You can invoke the GetUserProfileDirectory(...) located in Userenv.lib to abtain the directory like "C:\Documents and Settings\Joe".
- petter
Re: how to save file to Desktop?
You can use the SHGetFolderPath API to get the desktop folder.
Code:
Private Const CSIDL_DESKTOPDIRECTORY As Long = &H10
Private Declare Function SHGetFolderPath Lib "shfolder" _
Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, _
ByVal nFolder As Long, ByVal hToken As Long, _
ByVal dwFlags As Long, ByVal pszPath As String) As Long
Private Sub Command1_Click()
Dim strPath As String, lRet As Long
strPath = String(255, 0)
lRet = SHGetFolderPath(0, lngCSIDL, 0, SHGFP_TYPE_CURRENT, strPath)
strPath = Left$(strPath, InStr(1, strPath, Chr(0)) - 1)
MsgBox strPath
End Sub