Reputation: 595
I'm sending mass emails from a spreadsheet in Excel, using the Outlook reference library for my VBA code.
When I send the email, I need to save the conversation ID number to a cell in the sheet. How do I return this property from the email to excel?
Upvotes: 1
Views: 1782
Reputation: 12499
Once email is sent out, search sent folder and then grab the conversation ID.
Example here search by subject If olItem.Subject = "0m3r" Then
print ConvID to cell A1
Option Explicit
Sub ConvID()
Dim olNameSpace As Outlook.Namespace
Dim olApp As Outlook.Application
Dim olSentMail As Outlook.MAPIFolder
Dim olItem As Object ' Mail Item
Dim ConvID As Object ' ConversationID
Set olApp = CreateObject("Outlook.Application")
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olSentMail = olNameSpace.GetDefaultFolder(olFolderSentMail)
Set olItem = olApp.CreateItem(olMailItem)
For Each ConvID In olSentMail.Items
If olItem.Class = olMail Then ' ignores MeetingItem or ReportItem
If TypeName(ConvID) = "MailItem" Then
Set olItem = ConvID
If olItem.Subject = "0m3r" Then
Debug.Print olItem.ConversationID
Range("A1").Value = olItem.ConversationID
End If
End If
End If
Next
End Sub
Upvotes: 1