求当前路径,迅雷结帖!
CurrentPath = Access.CurrentProject.Path
这是求当前项目所在的路径。
问题:
类似的求当前计算机用户的MyDocument的路径该怎么写?
谢谢!
CurrentPath = ?
[解决办法]
参考:http://hi.baidu.com/xiaoxiaolq/blog/item/9c744edfec31441948540303.html
2009年02月08日 上午 02:24
'.......不用API
Private Sub Command2_Click() Const ssfDESKTOP = 0 '桌面 Const ssfPERSONAL = 5 '我的文档 Dim shl '.......还有很多 Set shl = CreateObject("shell.application") MsgBox shl.NameSpace(ssfDESKTOP).Self.Path MsgBox shl.NameSpace(ssfPERSONAL).Self.PathEnd Sub
[解决办法]
Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As LongPrivate Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As LongPrivate Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongPrivate Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongPrivate Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As LongConst MAX_LEN = 200 '字符串最大长度Const MYDOCUMENTS = &H5& '我的文档Private Sub Form_Load()Dim sTmp As String * MAX_LEN '存放结果的固定长度的字符串Dim nLength As Long '字符串的实际长度Dim pidl As Long '某特殊目录在特殊目录列表中的位置'*************************获得我的文档目录*********************************SHGetSpecialFolderLocation 0, MYDOCUMENTS, pidlSHGetPathFromIDList pidl, sTmpMsgBox Left(sTmp, InStr(sTmp, Chr(0)) - 1)End Sub