'Outlook emails into Excel using VBA

Issue: I'm trying to have pulled all of the information from Outlook into an Excel spreadsheet using VBA. I can pull the information from outlooks known as the Frequently -used fields. I cannot pull the ticket number column data into excel. The ticket number is a user-defined field.

Here is a screenshot of the Outlook email heading and email: enter image description here

Example of the Excel spreadsheet enter image description here

Any help is appreciated.

Code:

For Each objItem In myFolder.Items


        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.ItemProperties("Ticket Number").Value
         
         

       inc = inc + 1
         
    End If
    
    iRows = iRows + 1


Solution 1:[1]

First of all, Outlook folders may contain different item types - mails, appointments, documents and etc. So, in the loop you need to check whether you deal with a mail item or not before accessing any MailItem-specific properties.

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

The MailItem.ItemProperties property returns an ItemProperties collection that represents all standard and user-defined properties associated with the Outlook item.

 'Create a reference to the email item's properties collection.  
 Set objItems = objMail.ItemProperties  

So, you can iterate over all items in the collection to make sure the required property exists. So, if you find the property you can then ask for the Value.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eugene Astafiev