Tuesday, 16 July 2019

Outlook macro to interrupt a reply-all?


Is it possible to create an outlook macro such that when a user presses "Reply to All", there is a prompt saying something like "Your message will be sent to the following recipients: x,y,z. Are you sure? Y/N". The key question here is if there is even a hook available to interrupt the action at all.


Note that I am not looking to disable it or to buy an add-in.



Answer



Note: I'm working on 2007, but I think the code should transfer OK.


You can add an event handler via VBA to pick up the ReplyAll event. Something like the following:


Dim WithEvents insp As Outlook.Inspectors
Dim WithEvents mailItem As Outlook.MailItem

' This is called on Outlook startup
Private Sub Application_Startup()
Set insp = Application.Inspectors
End Sub

' This is called when a new Inspector is created. You use it to pick up on a new mail item event
Private Sub insp_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Size = 0 And Inspector.CurrentItem.Class = olMail Then
Set mailItem = Inspector.CurrentItem
End If
End Sub

' Called when you press ReplyAll
Private Sub mailItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
Dim msg As String
Dim result As Integer
msg = "Do you really want to reply to all?"
result = MsgBox(msg, vbYesNo, "Reply All Check")
If result = vbNo Then
Cancel = True
End If
End Sub

No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...