如何使用 VBA 获取对 Outlook 当前打开窗口中的邮件项的引用?

发布于 2024-10-01 08:21:59 字数 385 浏览 4 评论 0原文

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

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

我当前的选择逻辑如下:

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

I have a macro that works very well to place into folders / apply flags / set categories, but it only works on the current item selected in the explorer.

When I get an email alert on my desktop and click on it to open the email message, I would like to be able to run the same macro against that open item, but I can't find any documentation on how to access that object in a similar way to how I access the selected item in the explorer list.

My current selection logic looks like this:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热血少△年 2024-10-08 08:21:59

显然这是获取当前未清项目的代码:

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

Apparently this is the code to get the current open item:

If TypeName(Application.ActiveWindow) = "Inspector" Then
    Set Item = Application.ActiveWindow.CurrentItem
李白 2024-10-08 08:21:59

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

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

I did it like this. Declare the Item as a MailItem instead of an Object and then you get help from IntelliSense.

Dim CurrentMessage As MailItem
Set CurrentMessage = ActiveInspector.CurrentItem
CurrentMessage.HTMLBody = "[Insert HTML here]" 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文