简体   繁体   English

Outlook VBA如果主题匹配,如何遍历收件箱并从电子邮件地址列表

[英]Outlook VBA How to loop through inbox and list from email email address if subject matches

I'm trying to use Outlook VBA to loop through the inbox and list the from email address if the subject matches a string. 我正在尝试使用Outlook VBA循环收件箱,如果主题与字符串匹配,则列出来自电子邮件地址。 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? 有人知道为什么我在运行时出现类型不匹配错误?

As commented, try incorporating a test for MailItem in your code: 如评论所述,请尝试在代码中加入MailItem测试:

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: As suggested by Dmitry, you can also use: 编辑1:正如德米特里所建议的那样,你也可以使用:

If Item.Class = 43 Then

in place of 代替

If TypeOf Item Is Outlook.MailItem Then

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用带有两个电子邮件地址的vba将Outlook中的电子邮件主题复制到Excel? - Copy email subject in outlook to excel using vba with two email address? Use Excel VBA to move an Outlook Email from Inbox to a SubFolder of Archive based on Subject Line (Outlook 365 - Microsoft Exchange) - Use Excel VBA to move an Outlook Email from Inbox to a SubFolder of Archive based on Subject Line (Outlook 365 - Microsoft Exchange) 在 Outlook VBA 中更新电子邮件主题 - Updating email subject in Outlook VBA 如果关联名称包含字符串,如何从 Outlook VBA 的全局地址列表中提取 Email 地址 - How to Pull Email Address from Global Address List in Outlook VBA if the Associated Name contains String 如何使用 VBA 根据电子邮件主题提取 Outlook 电子邮件数据? - How to Extract outlook email data based on subject of the email using VBA? Outlook VBA,从主题中剪切电子邮件地址并将其作为收件人,然后转发邮件 - Outlook VBA, cut email address from subject and place it as recipient, then forward the message Excel VBA代码从底部的收件箱中读取Outlook电子邮件 - Excel vba code to read outlook email from inbox from bottom 如何根据 Outlook 插件中的收件箱点击获取电子邮件地址? - How to get email address based on inbox click in outlook addin? 如何从 Word VBA 的电子邮件地址设置 Outlook - How to set Outlook From email address from Word VBA VBA:在非默认Outlook收件箱中搜索电子邮件吗? - VBA: Search email in non default outlook inbox?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM