在 Outlook 中打开文件对话框 (VBA) 错误 438

Open File Dialog in Outlook (VBA) Error 438

我正在尝试通过 VBA 在 Outlook 中打开文件对话框。 (展望 2010)

使用以下代码我得到一个错误:

Runtime error 438. Object doesn't support this property or method

Private Sub btn_openPST_Click()
    Dim oFileDialog As FileDialog
    Set oFileDialog = myAppl.FileDialog(msoFileDialogFilePicker)
    With oFileDialog
        .Title = "Select your PST File"
        .ButtonName = "Ok"
        .Show
    End With
End Sub

myAppl 是一个 Outlook.Application 对象:

Dim myAppl As Outlook.Application
Set myAppl = CreateObject("Outlook.Application")

我认为 Outlook 无法打开文件选择器。我的解决方法是打开 Excel sheet 然后打开文件选择器,然后关闭 excel sheet。请尝试以下代码,并确保将 "Microsoft Excel 14.0 Object Library" 引用导入 Outlook。

Private Sub openFDinOutlook()

    Dim xlObj As Excel.Application
    Dim fd As Office.FileDialog

    Set xlObj = New Excel.Application
    xlObj.Visible = False
    Set fd = xlObj.Application.FileDialog(msoFileDialogFolderPicker)
    With fd
        .Title = "Select your PST File"
        .ButtonName = "Ok"
        .Show
    End With
    xlObj.Quit
    Set xlObj = Nothing


End Sub