Link to home
Start Free TrialLog in
Avatar of krashklown
krashklown

asked on

ReplyAll event in Outlook2000

I need to capture the ReplyAll event in Outlook2000 of a mailitem and then display a dialog box to ask the user if they REALLY want to REPLYALL.

I have some code, but it works only when you hit the Send button (and then only if you manually initialize the procedure for the active mailitem).  
I need the dialog box to display right after they choose ReplyALL (any of the 4 ways you can do a ReplyAll).

This needs to run on an non-admin PC(s).

Here's what I have:
__
Public WithEvents myItem As MailItem
__
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Initialize_Handler
End Sub
__
Sub Initialize_Handler()
    Set myItem = Application.ActiveInspector.CurrentItem
End Sub
__
Private Sub myItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
    Dim mymsg As String
    Dim myResult As Integer
    mymsg = "Do you really want to reply to all original recipients?"
    myResult = MsgBox(mymsg, vbYesNo, "xxxxx")
    If myResult = vbNo Then
        Cancel = True
    End If
End Sub

Avatar of David Lee
David Lee
Flag of United States of America image

Greetings, krashklown.

I see two problems.  First, you're only running the Initialize_Handler when the item is actually sent.  That's too late.  Second, Initialize_Handler is intended to be a generic name for whatever routine actually initializes the handler.  It isn't intended to be the actual name of a subroutine.  Try this instead.  This code sets up a watch on the Inspectors collection.  When a new Inspector is added, i.e. whenever a new window is opened, the NewInspector event fires and initializes a handler for the item in the Inspector if it's a mail item.  The mail item handler then monitors for a ReplyAll event.  If it sees one, then it runs your code.  I tested this on my system, Outlook 2003, and it worked exactly as described.  There is one flaw though.  If you open a message it initializes the mail item handler.  If you then open a second mail item it will overwrite the handler with its own handler.  If you then click ReplyAll on the first message your code won't run.  Avoiding this problem requires writing more code to build a collection of mail item handlers and then cleaning them up as each Inspector is closed.  


Private WithEvents olkInspectors As Outlook.Inspectors, _
    WithEvents olkMessage As Outlook.MailItem

Private Sub Application_Startup()
    Set olkInspectors = Application.Inspectors
End Sub

Private Sub olkInspectors_NewInspector(ByVal Inspector As Inspector)
    If Inspector.CurrentItem.Class = olMail Then
        Set olkMessage = Inspector.CurrentItem
    End If
End Sub

Private Sub olkMessage_ReplyAll(ByVal Response As Object, Cancel As Boolean)
    Dim mymsg As String
    Dim myResult As Integer
    mymsg = "Do you really want to reply to all original recipients?"
    myResult = MsgBox(mymsg, vbYesNo, "xxxxx")
    If myResult = vbNo Then
        Cancel = True
    End If
End Sub


Cheers!
Avatar of krashklown
krashklown

ASKER

hmmm....I can't get any macros to run on my Outlook2003!  Frustrating!

THANKS!!
I ran the code on a PC with Outlook2000.  Works well, but 2 questions:

1. This works fine if the user opens the mail item (into it's mail dialog box) from Outlook's main (list view) window.  But is there a way to grap the ReplyAll event while the email is still listed in Outlook's main window (either when CTRL+SHIFT+R or Actions, Reply to All are selected)?   This is the main thing.
2.  Which macro security level would this work for?
3.  How come I didn't think of it?  :)  
You're welcome.  Not sure what the issue is with 2003.  Here are answers to your specific questions/statements.

1.  Good point.  Try this revised code.  It's closer to what you want than the first version, but it's got a couple of problems.  There's still the issue of what happens if you open multiple items and this one uses the Explorer object instead of the Inspector.  As you select items in the Outlook window it grabs the selected item and watches it.  No matter how you try to do a ReplyAll it intercepts it.  The other issue is that you have to open a separate Explorer window to initiate the Explorer handler.  There's got to be a way to grab the Explorer created when Outlook first opens, but I'm missing it at the moment.

Private WithEvents olkExplorers As Outlook.Explorers, _
    WithEvents olkExplorer As Outlook.Explorer, _
    WithEvents olkMessage As Outlook.MailItem

Private Sub Application_Startup()
    Set olkExplorers = Application.Explorers
End Sub

Private Sub olkExplorer_SelectionChange()
    If olkExplorer.Selection.Item(1).Class = olMail Then
        Set olkMessage = olkExplorer.Selection.Item(1)
    Else
        Set olkMessage = Nothing
    End If
End Sub

Private Sub olkExplorers_NewExplorer(ByVal Explorer As Explorer)
    Set olkExplorer = Explorer
End Sub

Private Sub olkMessage_ReplyAll(ByVal Response As Object, Cancel As Boolean)
    Dim mymsg As String
    Dim myResult As Integer
    mymsg = "Do you really want to reply to all original recipients?"
    myResult = MsgBox(mymsg, vbYesNo, "xxxxx")
    If myResult = vbNo Then
        Cancel = True
    End If
End Sub

2.  In Outlook 2003 you need to set the security level down to Medium to run any unsigned macros.

3.  Sorry, can't answer that one!
Thanks, I'll try that today.
?s

1.  The Outlook.Inspectors lines should still be there to trap the new Inspectors?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I found the way (with some help) with ActiveExplorer.CommandBars and the ReplyAll ID.

Thanks David for ALL your help.
You're welcome.  Glad you got an answer.
Please post the complete final code.