In this edition of How to Make Outlook More Like GMail, I address the problem of replying to a message that you have sent. Inexplicably, Outlook creates a message addressed to you. That make sense from the standpoint that a reply to should be addressed to the sender. But then there’s the whole common sense thing. You know that thing where you wouldn’t send an email to yourself.
I’m a chronic reply-er to my own sent messages. I send a message to someone that omits some key information like, oh I don’t know, the attachment, and need to send a quick follow up.
In general, I need to monitor newly created email messages, see if they’re addressed to me, and then figure out to whom they should be addressed. That starts with creating an Inspectors variable declared WithEvents. The WithEvents keyword exposes the events of the object declared. In the ThisOutlookSession module:
Private WithEvents olInsp As Inspectors
Private Sub Application_Startup()
Set olInsp = Application.Inspectors
End Sub
Now by using the dropdown boxes at the top of the code module, I can select olInsp from the left and NewInspector (the only event for this type of object) from the right. I cobbled this next bit of code from various places, so not only will I not be giving proper attribution, but I don’t know what it all means either.
Private Sub olInsp_NewInspector(ByVal Inspector As Inspector)
Dim olMi As MailItem
Dim olParent As MailItem
Dim olRecip As Recipient
If Inspector.currentItem.Size = 0 And Inspector.currentItem.Class = olMail Then
Set olMi = Inspector.currentItem
If olMi.Recipients.Count = 1 Then
If olMi.Recipients.Item(1).Name = "Dick Kusleika" Then
Set olParent = FindParentMessage(olMi)
If Not olParent Is Nothing Then
olMi.Recipients.Remove 1
For Each olRecip In olParent.Recipients
olMi.Recipients.Add olRecip.Name
Next olRecip
olMi.Recipients.ResolveAll
End If
End If
End If
End If
End Sub
I’m not sure why (or if) I need to check that the size of the item is zero, but there it is. The second part of the If statement makes sure it’s email because an Inspector can hold any type of item. Next I check that there is only one Recipient and that it’s me. The FindParentMessage sub is shown below and it finds the message I’m replying to.
As long as everything works up to this point, I’m removed as the only Recipient and every recipient from the parent message is added. To find the parent message, I use the following code, which I borrowed from Sue Mosher. Sue says
The key to finding the parent message for a reply or forward is knowing that all messages in a conversation have the same ConversationTopic value, while the ConversationIndex is increased by 5 bytes with each exchange.
Function FindParentMessage(msg As Outlook.MailItem) As Outlook.MailItem
Dim sFind As String
Dim sIndex As String
Dim olFldr As Outlook.MAPIFolder
Dim olItems As Outlook.Items
Dim olMi As Object
sIndex = Left$(msg.ConversationIndex, Len(msg.ConversationIndex) - 10)
If Application.ActiveInspector Is Nothing Then
Set olFldr = Application.ActiveExplorer.Selection.Item(1).Parent
Else
Set olFldr = Application.ActiveInspector.currentItem.Parent
End If
sFind = "[ConversationTopic] = " & Chr$(34) & msg.ConversationTopic & Chr$(34)
Set olItems = olFldr.Items.Restrict(sFind)
For Each olMi In olItems
If olMi.Class = olMail Then
If olMi.ConversationIndex = sIndex Then
Set FindParentMessage = olMi
Exit For
End If
End If
Next olMi
End Function
I could reply from an open message (ActiveInspector) or from a list of messages (ActiveExplorer) and I get the folder depending on which it was. I find all of the messages in that folder with the same ConversationTopic, then loop through them to determine which has the correct ConversationIndex.
And that’s it. Now when I reply to a message I’ve sent, it’s addressed properly.
I find Outlook 2010 does all for this for you?
Very cool Outlook VBA programming Dick.
I created an Outlook addin some time ago and it’s very powerful to be able to capture certain messages and handle the attachments.
I don’t quite see the need for your particular set of code here as I just do a REPLY-ALL to my sent message and remove my name.
Small tip, restart Outlook before first use.
Note that message topics with double quotes might foul sFind, e.g. subject
Revolution #”9″
Try
On Error GoTo err1FindParentMessage
Set olItems = olFldr.Items.Restrict(sFind)
On Error GoTo 0
For Each olMi In olItems
If olMi.Class = olMail Then
If olMi.ConversationIndex = sIndex Then
Set FindParentMessage = olMi
Exit For
End If
End If
Next olMi
Exit Function
err1FindParentMessage:
If Err.Number = -2147352567 Then MsgBox "Did not remove """ & olInsp.Session.CurrentUser.Name & """ from recipients"
End FunctionYour code works for alt-R (reply), making alt-R work like alt-L (reply all) but sans the stupid addressing to myself. Here's another approach, where
alt-L works like gmail,
alt-R really does reply to myself
Private Sub olInsp_NewInspector(ByVal Inspector As Inspector)
Dim olMi As MailItem, olParent As MailItem
If Inspector.CurrentItem.Size = 0 And Inspector.CurrentItem.Class = olMail Then
Set olMi = Inspector.CurrentItem
With olMi 'With Inspector.CurrentItem may be more efficient (untested)
If .Recipients.Count > 1 Then
If .Recipients.Item(1).Name = olInsp.Session.CurrentUser.Name Then
Set olParent = FindParentMessage(olMi)
If Not olParent Is Nothing Then
.Recipients.Remove 1 'remove my own name
End If
End If
End If
End With
End If
End SubThat said, great stuff. Yet again, as again and again, you've zoned in on something that I've asked thousands of times, saying "those $%&ing Microsoft Office clueless numbnuts." I don't know why Jensen hasn't had you assassinated. And your answer is, as always, thorough, has proper attributions, code is tight and neat, and it works! Please repeat the above commendations for many many dozens of similar posts I've silently yet elatedly suckled on (along with your legendary crop of commenters.)
OL07. (I'm pretty sure it's 2007; the clown crew removed alt-H,A. No help about! I'm not kidding!)
actually, in outlook 2013 this half way works like it should. if you click reply on an email you sent, it will address it to yourself.
but, if you click reply all, it will actually address it to the person that you originally sent it to.
now, why reply all does this and not reply, i have no idea.