返回自定义Outlook属性值



背景:使用VBA处理项目,将Outlook电子邮件中的信息提取到Excel工作表中。

问题:除了票号,我可以得到所有的值。票号是我们创建的自定义列标题。

代码来源:https://www.encodedna.com/excel/how-to-parse-outlook-emails-and-show-in-excel-worksheet-using-vba.htm

For Each objItem In myFolder.Items
If objItem.Class = olMail Then

Dim objMail As Outlook.MailItem
Set objMail = objItem

Cells(iRows, 1) = objMail.SenderEmailAddress
Cells(iRows, 2) = objMail.Subject
Cells(iRows, 3) = objMail.ReceivedTime
Cells(iRows, 4) = objMail.body
Cells(iRows, 5) = objMail.Categories
Cells(iRows, 6) = objMail.ticketnumber
End If
iRows = iRows + 1
Next

我尝试过的变体:

ObjectMail.ticketnumber
ObjectMail.TicketNumber
ObjectMail.ticket_Number

您可以尝试在UserProperties集合中查找。相应的属性返回代表Outlook项目的所有用户属性的UserProperties集合。UserProperties.Find方法查找并返回请求的属性名称的UserProperty对象(如果存在(。以下是MSDN声明:

如果使用Find查找自定义属性并且调用成功,则返回UserProperty对象。如果失败,则返回Null(在Visual Basic中为Nothing(。

如果使用Find查找内置属性,请为Custom参数指定False。如果调用成功,它将属性作为UserProperty对象返回。如果调用失败,则返回Null(在Visual Basic中为Nothing(。如果为Custom指定True,则调用找不到内置属性并返回Null(在Visual Basic中为Nothing(。

您也可以检查传输消息头,以确保此类属性存在(PR_TRANSPORT_MESSAGE_HEADERS(:

propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E")

尝试:

objMail.ItemProperties("TicketNumber").Value

ItemProperties/UserProperties:概述

https://learn.microsoft.com/en-us/office/vba/outlook/how-to/navigation/properties-overview

最新更新