[英]How to pull from Outlook Address book based on values in Excel (VBA)
[英]Returning outlook sender address from VBA in Excel
我從這里的答案中復制了以下代碼。 當收到新的 email 並從 excel 內運行時,它會觸發 myItems_ItemAdd。 (注意我不能直接從 Outlook 調用新郵件事件)
Private WithEvents myItems As Outlook.Items
Private Sub Class_Initialize()
Dim oNS As Namespace
Dim myOL As Outlook.Application
Set myOL = New Outlook.Application
Set oNS = myOL.GetNamespace("MAPI")
Set myItems = oNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub myItems_ItemAdd(ByVal Item As Object)
Debug.Print "Got_EMAIL!!!"
End Sub
然后我想像主題一樣訪問 email 的各種其他屬性。 例如,這有效:
Private Sub myItems_ItemAdd(ByVal Item As Object)
Debug.Print "Got_EMAIL!!!"
Debug.Print Item.Subject
End Sub
我會根據文檔認為 MailItem (哪個項目是?)應該可以通過以下方式訪問:
Debug.Print Item.Sender
但這會導致運行時錯誤“287”
我也試過行:
Debug.Print Item.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10130102")
Debug.Print Item.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0C1F001E")
Debug.Print Item.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS)
哪個有錯誤:
當我檢查項目 object 時,我注意到 Sender 和 MAPIObject 都是空的。 我一直無法找到為什么可以通過 Property Accessor 訪問 Sender 屬性的答案。
如何訪問發件人的 email 地址?
*** 更新 **
Item.Sender.Address 導致運行時錯誤“287”
如前所述, Sender 和 MAPIObject 都是空的:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.