如何使用 VBA 在 Outlook 中当前打开的窗口中获取对邮件项目的引用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4134967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you get a reference to the mail item in the current open window in Outlook using VBA?
提问by Matt Connolly
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
回答by Matt Connolly
Apparently this is the code to get the current open item:
显然这是获取当前打开项目的代码:
If TypeName(Application.ActiveWindow) = "Inspector" Then
Set Item = Application.ActiveWindow.CurrentItem
回答by user2038505
I did it like this. Declare the Item as a MailItem instead of an Object and then you get help from IntelliSense.
我是这样做的。将 Item 声明为 MailItem 而不是 Object,然后您会从 IntelliSense 获得帮助。
Dim CurrentMessage As MailItem
Set CurrentMessage = ActiveInspector.CurrentItem
CurrentMessage.HTMLBody = "[Insert HTML here]"