Gmail as "Send and Archive" in Outlook. How to get to the "parent" letter in response

Responding to a letter 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 am looking to go to the "test" to which the email is sent, so it can be automatic. Move (d) to the archive folder.

+3
source share
2 answers

That would be better in Outlook 2010, I think. For earlier versions, I believe that you need 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
+2
source
Item.ConversationTopic

- , .

+2

Source: https://habr.com/ru/post/1734340/


All Articles