[英]Copy email subject in outlook to excel using vba with two email address?
[英]Outlook VBA How to loop through inbox and list from email email address if subject matches
我正在尝试使用Outlook VBA循环收件箱,如果主题与字符串匹配,则列出来自电子邮件地址。 到目前为止,这是谷歌搜索,但它不起作用:
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
有人知道为什么我在运行时出现类型不匹配错误?
如评论所述,请尝试在代码中加入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
编辑1:正如德米特里所建议的那样,你也可以使用:
If Item.Class = 43 Then
代替
If TypeOf Item Is Outlook.MailItem Then
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.