Background: Working on a project to pull information from outlook emails into an excel sheet using vba.
Problem: I'm able to get all of the label headings but Ticket Number. The ticket number is a custom column heading that we have created.
Code to reference
Current code:
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
Different variations that I have tried:
ObjectMail.ticketnumber
ObjectMail.TicketNumber
ObjectMail.ticket_Number
Thanks for your help!
CodePudding user response:
You can try looking in the UserProperties collection. The corresponding property returns the UserProperties
collection that represents all the user properties for the Outlook item. The UserProperties.Find method locates and returns a UserProperty
object for the requested property name, if it exists. Here is what MSDN states:
If you use Find to look for a custom property and the call succeeds, it returns a UserProperty object. If it fails, it returns Null (Nothing in Visual Basic).
If you use Find to look for a built-in property, specify False for the Custom parameter. If the call succeeds, it returns the property as a UserProperty object. If the call fails, it returns Null (Nothing in Visual Basic). If you specify True for Custom, the call does not find the built-in property and returns Null (Nothing in Visual Basic).
Also you may check the transport message headers to make sure such property exists (PR_TRANSPORT_MESSAGE_HEADERS
):
propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E")
CodePudding user response:
Try:
objMail.ItemProperties("TicketNumber").Value
Overview of ItemProperties/UserProperties:
https://docs.microsoft.com/en-us/office/vba/outlook/how-to/navigation/properties-overview