Responding to an email with the subject line "test", with this code...
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeName(Item) = "MailItem" Then
Debug.Print Item.Subject
Debug.Print Item.Parent
End If
End Sub
...returns this.
Inbox
RE: test
I'm looking to get to "test", which is the email being responded to so it can be automatically .Move(d) to an archive folder.
This would be better in Outlook 2010, I think. For earlier versions, I believe you want this code which is quoted directly from http://www.outlookcode.com/codedetail.aspx?id=1714
Function FindParentMessage(msg As Outlook.MailItem) _
As Outlook.MailItem
Dim strFind As String
Dim strIndex As String
Dim fld As Outlook.MAPIFolder
Dim itms As Outlook.Items
Dim itm As Outlook.MailItem
On Error Resume Next
strIndex = Left(msg.ConversationIndex, _
Len(msg.ConversationIndex) - 10)
Set fld = Application.Session.GetDefaultFolder(olFolderInbox)
strFind = "[ConversationTopic] = " & _
Chr(34) & msg.ConversationTopic & Chr(34)
Set itms = fld.Items.Restrict(strFind)
Debug.Print itms.Count
For Each itm In itms
If itm.ConversationIndex = strIndex Then
Debug.Print itm.To
Set FindParentMessage = itm
Exit For
End If
Next
Set fld = Nothing
Set itms = Nothing
Set itm = Nothing
End Function
Item.ConversationTopic
is the property you're looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With