Outlook VBA - 获取当前活动(或打开)电子邮件的详细信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2223171/
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
Outlook VBA - Get Details Of Current Active (Or Open) Email
提问by Kezzer
I am completely stuck as to how to retrieve details of an email which is either currently selected or open. In fact, I can't find any details on how to access an email. It seems you can traverse the entire folder structure and get all emails, but that doesn't really help me.
我完全不知道如何检索当前选择或打开的电子邮件的详细信息。事实上,我找不到有关如何访问电子邮件的任何详细信息。似乎您可以遍历整个文件夹结构并获取所有电子邮件,但这并没有真正帮助我。
I don't suppose I can get some pointers?
我想我不能得到一些指点?
And yes, I hate VBA as much as the next developer, but unfortunately about 0.1% of my work involves integration with Outlook.
是的,我和下一个开发人员一样讨厌 VBA,但不幸的是,我大约 0.1% 的工作涉及与 Outlook 的集成。
Cheers.
干杯。
回答by 76mel
To get the currently selected emails by looking at the Selectionobject of the Explorer.
通过查看资源管理器的选择对象来获取当前选择的电子邮件。
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Set myOlExp = Application.ActiveExplorer
Set myOlSel = myOlExp.Selection
The selection object can contain many items and also contain Items that are of other types than mail (IPM.Note) i.e calendar apps etc. So if you only want mail items you can take a look at the item MessageClass
选择对象可以包含许多项目,还包含邮件(IPM.Note)以外的其他类型的项目,即日历应用程序等。因此,如果您只想要邮件项目,您可以查看项目 MessageClass
As for the current email that is trickier as you can multuiple of these open if you just want the top most you can use the Application.ActiveInspectorotherwise you should look at the Inspectors Collectionof the Application object. You can then get the "item" from the CurrentItemproperty off the Inspector(remember these can be non mails as well)
至于当前的电子邮件,它比较棘手,因为如果您只想要最上面的,您可以打开多个这些电子邮件,您可以使用Application.ActiveInspector否则您应该查看Application 对象的Inspectors 集合。然后,您可以从Inspector的CurrentItem属性中获取“项目” (请记住,这些也可以是非邮件)
Hope full that will get you going
希望完全可以让你前进

