gpt4 book ai didi

vba - Outlook VBA 如何循环浏览收件箱并从电子邮件地址列表(如果主题匹配)

转载 作者:行者123 更新时间:2023-12-03 02:13:39 24 4
gpt4 key购买 nike

我正在尝试使用 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

Edit1:根据 Dmitry 的建议,您还可以使用:

If Item.Class = 43 Then

代替

If TypeOf Item Is Outlook.MailItem Then

关于vba - Outlook VBA 如何循环浏览收件箱并从电子邮件地址列表(如果主题匹配),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24321752/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com