Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gmail like "Send and Archive" in Outlook. How to get to the "parent" email when replying

Tags:

vba

outlook

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.

like image 643
GollyJer Avatar asked Nov 27 '25 08:11

GollyJer


2 Answers

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
like image 161
Fionnuala Avatar answered Nov 29 '25 23:11

Fionnuala


Item.ConversationTopic

is the property you're looking for.

like image 26
Dick Kusleika Avatar answered Nov 29 '25 23:11

Dick Kusleika



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!