Outlook VBA 如果主题匹配,如何循环浏览收件箱和电子邮件地址列表 [英] Outlook VBA How to loop through inbox and list from email email address if subject matches
本文介绍了Outlook VBA 如果主题匹配,如何循环浏览收件箱和电子邮件地址列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果主题与字符串匹配,我正在尝试使用 Outlook VBA 循环浏览收件箱并列出发件人电子邮件地址.到目前为止,通过谷歌搜索得到了这个,但它不起作用:
I'm trying to use Outlook VBA to loop through the inbox and list the from email address if the subject matches a string. Got this so far from googling, but it's not working:
Dim objNS As Outlook.NameSpace
Set objNS = GetNamespace("MAPI")
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
Dim oFolder As Outlook.MAPIFolder
Dim oMail As Outlook.MailItem
For Each oMail In Items
Debug.Print oMail.SenderEmailAddress
Next
有谁知道为什么我运行这个时会出现类型不匹配错误?
Anybody know why I get a Type Mismatch error when I run this?
推荐答案
如评论中所述,尝试在您的代码中加入对 MailItem 的测试:
As commented, try incorporating a test for MailItem in your code:
Dim objNS As Outlook.NameSpace: Set objNS = GetNamespace("MAPI")
Dim olFolder As Outlook.MAPIFolder
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
Dim Item As Object
For Each Item In olFolder.Items
If TypeOf Item Is Outlook.MailItem Then
Dim oMail As Outlook.MailItem: Set oMail = Item
Debug.Print oMail.SenderEmailAddress
End If
Next
Edit1:根据 Dmitry 的建议,您还可以使用:
As suggested by Dmitry, you can also use:
If Item.Class = 43 Then
代替
If TypeOf Item Is Outlook.MailItem Then
这篇关于Outlook VBA 如果主题匹配,如何循环浏览收件箱和电子邮件地址列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文