Job/Life/Reputation protector 2.0

Back in January I posted some simple VBA code for adding an “are you sure?” type question to the Reply To All button in Outlook.  Since then I have received a few suggestions for improving the code, one of the most common of which was to add to the question box the list of names that the mail will be sent to.  So, as requested, you can find below the updated code! 

image 

Just place this code in a module in Outlook (you can get to the VBA editor by pressing ALT+F11) and then assign it a button on the toolbar:

Sub ReplyToAllGuard()

    On Error GoTo ReplyAllErr
    Dim myOlApp As Outlook.Application
    Dim myFolder As Outlook.MAPIFolder
    Dim myItem As Outlook.MailItem
    Dim ReplyMail  As Outlook.MailItem
    Dim i As Integer

    Set myOlApp = Application
    Set myFolder = myOlApp.ActiveExplorer.CurrentFolder

    iCount = myOlApp.ActiveExplorer.Selection.Count

    For i = 1 To iCount

        Set myItem = myOlApp.ActiveExplorer.Selection.Item(1)
        Set ReplyMail = myItem.ReplyAll

    Next i

    Dim mymsg As String
    Dim strRecipients As String
    Dim ReplyQ As Integer
   
    For Each strRec In ReplyMail.Recipients

        strRecipients = strRecipients & strRec & Chr(13)

    Next

    mymsg = "You just clicked Reply to All.  Are you sure that this is what you want to do?  The following recipients will receive this mail:" & _
            Chr(13) & Chr(13) & strRecipients

    ReplyQ = MsgBox(mymsg, vbYesNo, "Job/Life/Reputation protector")

    If ReplyQ = vbNo Then

        Set ReplyMail = Nothing
        Exit Sub

    Else

        myItem.UnRead = False
        ReplyMail.Display

    End If

ReplyAllErr:

    If Err.Number = -2147467259 Then

        MsgBox "The sender has prevented you from being able to reply to all recipients.", vbOKOnly, "Job/Life/Reputation protector"

    End If

    Exit Sub

End Sub

 

I also made one another change to the code in order to prevent receiving the error “A program is trying to access e-mail address information stored in Outlook”.  This error is generated because Outlook has detected a possible security risk because some ‘unknown’ VBA code is trying to harvest the e-mail addresses from an e-mail; in this case though, we actually want it to!

 image

Basically, instead of initiating a new Outlook session in memory, the code now reuses the existing instance of Outlook, thereby not generating a security problem as the message box is suggesting.

 

Edit: I amended the code to fix an oversight by me where the code did not clean up after itself!  Also, the mail now marks itself as read after you reply - Thanks JP for pointing it out.