关于 Outlook 选择目录对话框的问题

需要在 Outlook 下通过VBA打开一个选择目录的对话框,刚开始搜索到的解决方案类似如下代码

Dim msDialog As Office.FileDialog
Set msDialog = Application.FileDialog(msoFileDialogFilePicker)
msDialog.Show

但是经过很多次实验,Outlook 2010中根本没有 Application.FileDialog 这样的属性方法。这条路是无法行通的!!!

最后的解决方案是如下代码

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
As Long

Private Const BIF_RETURNONLYFSDIRS = &H1
Public Function BrowseFolder(szDialogTitle As String) As String
Dim X As Long, bi As BROWSEINFO, dwIList As Long
Dim szPath As String, wPos As Integer

With bi
.hOwner = hWndAccessApp
.lpszTitle = szDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With

dwIList = SHBrowseForFolder(bi)
szPath = Space$(512)
X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)

If X Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1)
Else
BrowseFolder = vbNullString
End If
End Function

Sub dd()
Dim Str As String

Str = BrowseFolder("c:\\")

Debug.Print Str

End Sub

代码来自 http://access.mvps.org/access/api/api0002.htm

opendialog

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注