【发布时间】:2020-10-02 03:44:00
【问题描述】:
从 W7 上的 Office 2010 升级到 W10 上的 Office 365 后,以下代码停止工作。
Option Explicit
Sub test()
Dim OL As Outlook.Application
Dim ST As Outlook.Store
Dim DSI As Outlook.Folder
Dim Email As Outlook.MailItem
Set OL = CreateObject("Outlook.Application")
'Find Primary Mailbox
For Each ST In OL.GetNamespace("MAPI").Stores
If ST.ExchangeStoreType = olPrimaryExchangeMailbox Then
Set DSI = ST.GetDefaultFolder(olFolderSentMail)
Exit For
End If
Set ST = Nothing
Next
Const PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
For Each Email In DSI.Items
Debug.Print Email.Sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS)
Next
Set Email = Nothing
Set DSI = Nothing
Set ST = Nothing
Set OL = Nothing
End Sub
它现在在此行返回 287 运行时错误“应用程序定义或对象定义错误”。
Debug.Print Email.Sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS)
我的研究表明这是一个信任问题;所以我尝试在代码中添加签名,但没有奏效。
我让它工作的唯一方法是直接在 Outlook VBA 上运行,并将签名应用于代码。但我需要能够从 excel VBA 运行它。
有什么建议吗?
代码的目的是识别默认发送邮件文件夹中已使用共享邮箱发送的电子邮件,并将它们移动到单独的文件夹(代码已在上面被删减,仅显示手头的错误) .正如我所说,代码在升级之前运行良好。
【问题讨论】:
-
PropertyAccessor是MailItem的属性。它不是MailItem.Sender的属性。删除.Sender。 -
我的实验发现
MailItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E")和MailItem.SenderEmailAddress之间没有区别。 -
你错了 - Sender 属性返回一个具有
PropertyAccessor属性的 AddressEntry 实例。所以,代码是正确的! -
@TonyDallimore 每次从不同邮箱发送邮件时都会有所不同(例如,“代表”邮件发送)
-
@EugeneAstafiev。你是对的,
Sender确实有属性PropertyAccessor。我从没想过要这么感谢你提供的信息。但是,我无法使用MailItem或MailItem.Sender在我的系统上获取问题中的架构地址。你知道我在哪里可以找到MailItem.Sender的架构列表吗?
标签: excel vba outlook office365 digital-signature