【问题标题】:Where is Outlook's save FileDialog?Outlook 的保存文件对话框在哪里?
【发布时间】:2010-10-22 09:02:20
【问题描述】:

我正在开发一个 Outlook 加载项,该加载项需要 Office 特定的 FileDialog 才能与 Sharepoint 站点进行互操作;公用文件对话框不具备互操作性。我知道 Word 和 Excel 在 Globals.ThisAddIn.Application.Application 下都有一个 get_fileDialog 方法,但 Outlook 似乎没有。如何启动 Outlook FileDialog?有可能吗?

【问题讨论】:

    标签: outlook office-2007 outlook-2007 outlook-addin


    【解决方案1】:

    Microsoft Common Dialog

    如果您安装了 COMDLG32.OCX(“通用对话框 ActiveX 控件”),那么您可以使用它 - 此处通过示例对其进行了说明。 (向下滚动到标题为“图 2:不要尝试在 Word 中选择多个文件!”的屏幕截图)。

    【讨论】:

      【解决方案2】:

      看来 Outlook 的 Application 对象不提供 FileDialog。但是,如果您愿意获得 Excel 参考,一个简单的解决方法是:

      Dim fd As FileDialog
      Set fd = Excel.Application.FileDialog(msoFileDialogFolderPicker)
      Dim folder As Variant    
      If fd.Show = -1 Then
          For Each folder In fd.SelectedItems
              Debug.Print "Folder:" & folder & "."
          Next
      End If
      

      【讨论】:

        【解决方案3】:
        'Add a "Module". Then add the declarations like this to it.
        
        Option Explicit
        Private Declare Function GetOpenFileName _
                        Lib "comdlg32.dll" _
                        Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
        Private Type OPENFILENAME
            lStructSize As Long
            hwndOwner As Long
            hInstance As Long
            lpstrFilter As String
            lpstrCustomFilter As String
            nMaxCustFilter As Long
            nFilterIndex As Long
            lpstrFile As String
            nMaxFile As Long
            lpstrFileTitle As String
            nMaxFileTitle As Long
            lpstrInitialDir As String
            lpstrTitle As String
            flags As Long
            nFileOffset As Integer
            nFileExtension As Integer
            lpstrDefExt As String
            lCustData As Long
            lpfnHook As Long
            lpTemplateName As String
        End Type
        
        Public Function MyOpenFiledialog() As String
            Dim OFName As OPENFILENAME
            OFName.lStructSize = Len(OFName)
            'Set the parent window
            OFName.hwndOwner = Application.hWnd
            'Set the application's instance
            OFName.hInstance = Application.hInstance
            'Select a filter
            OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
            'create a buffer for the file
            OFName.lpstrFile = Space$(254)
            'set the maximum length of a returned file
            OFName.nMaxFile = 255
            'Create a buffer for the file title
            OFName.lpstrFileTitle = Space$(254)
            'Set the maximum length of a returned file title
            OFName.nMaxFileTitle = 255
            'Set the initial directory
            OFName.lpstrInitialDir = "C:\"
            'Set the title
            OFName.lpstrTitle = "Open File - VB Forums.com"
            'No flags
            OFName.flags = 0
            'Show the 'Open File'-dialog
            If GetOpenFileName(OFName) Then
                MsgBox "File to Open: " + Trim$(OFName.lpstrFile)
                MyOpenFiledialog = Trim$(OFName.lpstrFile)
            Else
                MsgBox "Cancel was pressed"
                MyOpenFiledialog = vbNullString
            End If
        End Sub 'Usage:
        Private Sub Command1_Click()
            Text1.Text = MyOpenFiledialog
        End Sub
        

        【讨论】:

        • Outlook 不支持关闭应用程序的 FileOpen 对话。此外,www.slipstick.com 是提供提示和代码的最佳 Outlook 开发人员网站。
        • 我可能应该提到我使用的是 VSTO,而不是 VBA。无论如何,我不认为创建我自己的对话框会有所帮助,因为它需要 Office 对话框提供的真正特定的 SharePoint 功能。
        • 似乎对我不起作用(Outlook 2007)?我认为有一个小错字,函数'MyOpenFiledialog()'以'End Sub'终止-但我将其更改为'End Function',现在收到错误//运行时错误'438':对象不支持此属性或方法// - 按“DEBUG”会将我带到 //OFName.hwndOwner = Application.hWnd//
        【解决方案4】:
        Public Sub TestFileDialog()
            Dim otherObject As Excel.Application
            Dim fdFolder As office.FileDialog
        
            Set otherObject = New Excel.Application
            otherObject.Visible = False
            Set fdFolder = otherObject.Application.FileDialog(msoFileDialogFolderPicker)
            fdFolder.Show
            Debug.Print fdFolder.SelectedItems(1)
            otherObject.Quit
            Set otherObject = Nothing
        End Sub
        

        【讨论】:

          【解决方案5】:
          Private Sub multiEML2MSG()
          
          Const PR_ICON_INDEX = &H10800003
          
          Dim objPost As Outlook.PostItem
          Dim objSafePost As Redemption.SafePostItem
          Dim objNS As Outlook.NameSpace
          Dim objInbox As Outlook.MAPIFolder
          
          
          Set objNS = Outlook.GetNamespace("MAPI")
          Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
          Set objPost = objInbox.Items.Add(OlItemType.olPostItem)
          
          Set objSafePost = New Redemption.SafePostItem
          
          
          
              Dim xlObj As Excel.Application
              Dim fd As Office.FileDialog
          
              Set xlObj = New Excel.Application
          
              Set fd = xlObj.Application.FileDialog(msoFileDialogFolderPicker)
              With fd
                  .Title = "Select your PST File"
                  .ButtonName = "Ok"
                  .Show
          
                  If fd.SelectedItems.Count <> 0 Then
                      xDirect$ = fd.SelectedItems(1) & "\"
                      xFname$ = Dir(xDirect$, 7)
          
          
                      licznik = 1
                      Do While xFname$ <> ""
          
                      XPathEML = xDirect$ & xFname$
                      XPathMSG = Replace(XPathEML, ".eml", ".msg", , , vbTextCompare)
                      Debug.Print XPath, Replace(XPath, ".eml", ".msg", , , vbTextCompare)
          
          
                      objPost.Save
                      objSafePost.Item = objPost
                      objSafePost.Import XPathEML, Redemption.RedemptionSaveAsType.olRFC822
                      objSafePost.MessageClass = "IPM.Note"
                      objSafePost.Fields(PR_ICON_INDEX) = none
                      objSafePost.SaveAs XPathMSG, Outlook.OlSaveAsType.olMSG
          
          
          
                      xFname$ = Dir
                      licznik = licznik + 1
                  Loop
          
                  End If
              End With
          
              xlObj.Quit
              Set xlObj = Nothing
              Set objSafePost = Nothing
              Set objPost = Nothing
              Set objInbox = Nothing
              Set objNS = Nothing
          
          End Sub
          

          【讨论】:

          • 欢迎来到 Stack Overflow!虽然这段代码 sn-p 可以解决问题,但including an explanation 确实有助于提高帖子的质量。请记住,您正在为将来的读者回答问题,而这些人可能不知道您的代码建议的原因。也请尽量不要用解释性的 cmets 挤满你的代码,这会降低代码和解释的可读性!
          猜你喜欢
          • 1970-01-01
          • 2015-12-28
          • 2011-08-01
          • 2011-09-14
          • 2010-09-19
          • 1970-01-01
          • 1970-01-01
          • 2014-09-21
          • 1970-01-01
          相关资源
          最近更新 更多