【问题标题】:How do you get a reference to the mail item in the current open window in Outlook using VBA?如何使用 VBA 在 Outlook 中当前打开的窗口中获取对邮件项目的引用?
【发布时间】:2010-11-09 14:47:45
【问题描述】:

我有一个宏可以很好地放入文件夹/应用标志/设置类别,但它仅适用于资源管理器中选择的当前项目。

当我在桌面上收到电子邮件警报并单击它以打开电子邮件时,我希望能够针对该打开的项目运行相同的宏,但我找不到任何有关如何访问的文档该对象的访问方式与我访问资源管理器列表中所选项目的方式类似。

我当前的选择逻辑如下所示:

Dim Item As Object
Dim SelectedItems As Selection

Set SelectedItems = Outlook.ActiveExplorer.Selection
For Each Item In SelectedItems
    With Item
        'do stuff
    End With
Next Item

【问题讨论】:

    标签: vba outlook outlook-2007


    【解决方案1】:

    显然这是获取当前打开项目的代码:

    If TypeName(Application.ActiveWindow) = "Inspector" Then
        Set Item = Application.ActiveWindow.CurrentItem
    

    【讨论】:

      【解决方案2】:

      我是这样做的。将 Item 声明为 MailItem 而不是 Object,然后您会从 IntelliSense 获得帮助。

      Dim CurrentMessage As MailItem
      Set CurrentMessage = ActiveInspector.CurrentItem
      CurrentMessage.HTMLBody = "[Insert HTML here]" 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-01-16
        • 1970-01-01
        • 2019-08-15
        • 1970-01-01
        • 1970-01-01
        • 2023-03-13
        • 1970-01-01
        相关资源
        最近更新 更多