none
Reply All Warning

    質問

  • I've been tasked with creating an add-in for the office here where I work that warns the user they are doing a Reply All, and gives them the option to back out (Yes/No) kind of thing. There is some code out there and I've been able to create a VSTO project that partially works. The real challenge however comes in being familiar enough with the Outlook 2010 object library. There are at a minimum three different ways a user can execute a Reply All: From the message itself, from the right-click context menu, and also from the ribbon.

    Here follows the code I've scraped from the Interwebs. It is neither perfect nor complete. It does however work. I need to expand on this code however to capture (presumably by using WithEvents and creating the appropriate Events associated with Outlook) the other two means by which Reply All can be executed.

    Bear in mind, I know that Gavin's NoReplyAll project has a different purpose than the one I propose. It is however quite close, rather very close to what I need to do. There are unfortunately few other resources to turn to. The products out there currently either don't work completely, are flawed, or are ridiculously over-priced.

    Any guidance, help, or assistance would be GREATLY appreciated. Thank you.

    Public Class ThisAddIn
    
        Private WithEvents olkInspectors As Outlook.Inspectors
        Private WithEvents olkMessage As Outlook.MailItem
    
        Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
    
            Dim myOL As Outlook.Application
            myOL = Globals.ThisAddIn.Application
            olkInspectors = myOL.Inspectors()
            myOL = Nothing
    
        End Sub
    
        Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
    
            olkInspectors = Nothing
            olkMessage = Nothing
    
        End Sub
    
        Private Sub olkInspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles olkInspectors.NewInspector
    
            olkMessage = Nothing
            If Inspector.CurrentItem.Class = Outlook.OlObjectClass.olMail Then
                olkMessage = Inspector.CurrentItem
            End If
    
        End Sub
    
        Private Sub olkMessage_ReplyAll(ByVal Response As Object, ByRef Cancel As Boolean) Handles olkMessage.ReplyAll
    
            If MsgBox("Are you sure you want to Reply To All?", _
                      vbQuestion + vbYesNo, "Verify Reply to All (M&G)") = vbNo Then
                Cancel = True
            End If
    
        End Sub
    
    End Class
    


    2012年1月30日 15:27

すべての返信

  • I didn't even know that there was a way to intercept reply-all specifically - learn something new every day! Given its existence, I'm surprised that it doesn't handle all ways of invoking reply-all (have you verified that it actually doesn't?). It's possible to intercept any message as it's about to be sent (that's what I use for checking for missing attachments: maybe you could hook that send (add an event hander to Application.Send), which does seem to apply to all ways of sending emails, and then use some heuristic to identify a reply-all message (eg, off the top of my head, subject line starts with "RE:" and the TO address line contains more than some small number of people, or a group alias, though I don't know how you'd recognise that easily).

    2012年1月30日 16:58
  • It does kind-of-sorta work, but only after the message is opened. It's goofy and difficult to describe, you'd have to see for yourself.

    I was hoping to capture the events of the Explorer object actually. I know you mentioned using PowerShell to discover the object library, I typically use Office VBA to do the same, and was able to determine that Explorer refers to the folder/mailbox and that Selected refers to the item selected, of course. That's at least a 1/3 of the picture right there.

    The trick is gleaning what the Events are and how they are formed, especially the Handles portion.

    Here is some VBA code that grabs the selected item from the Explorer object, displays it and subsequently executes a Reply All. The hard part, for me at least, is translating this functionality into VB.Net code.

    Function TestMe()
    
    Dim m As MailItem
    
    Debug.Print Me.Explorers.Count
    Debug.Print Me.Explorers.Item(1).Caption
    Debug.Print Me.Explorers.Item(1).Selection.Count
    Me.Explorers.Item(1).Selection(1).Display
    Set m = Me.Explorers.Item(1).Selection(1).ReplyAll
    m.Display
    
    End Function


    • 編集済み ITMn0403 2012年1月30日 17:47
    2012年1月30日 17:15
  • A book like Eric Carter & Eric Lippert's "Visual Studio Tools for Office 2007" might help with the translation to .NET - I haven't got my copy in front of me and can't actually remember if it covers VB.NET or just C#. There are, of course, other VSTO books - one title that caught my eye was "VSTO for Mere Mortals: a VBA Developer's guide to Microsoft Office Visual Studio 2005 Tools for Office" - I've no idea how good this one is, and do bear in mind that some of VSTO did change between 2005 and 2007 versions.
    2012年1月31日 6:48
  • While some books may provide additional clues, and help. I wouldn't imagine they are in fact the solution. Helpful certainly. Thank you Gavin.
    2012年2月1日 13:46
  • I think this will do the trick:

    Public Class ThisAddIn Private WithEvents olkInspectors As Outlook.Inspectors Private WithEvents olkMessage As Outlook.MailItem Private WithEvents olkExplorer As Outlook.Explorer Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup Dim myOL As Outlook.Application myOL = Globals.ThisAddIn.Application olkInspectors = myOL.Inspectors() olkExplorer = myOL.ActiveExplorer myOL = Nothing End Sub Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown olkInspectors = Nothing olkMessage = Nothing olkExplorer = Nothing End Sub Private Sub olkInspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles olkInspectors.NewInspector olkMessage = Nothing If Inspector.CurrentItem.Class = Outlook.OlObjectClass.olMail Then olkMessage = Inspector.CurrentItem End If End Sub Private Sub olkExplorer_() Handles olkExplorer.SelectionChange

    If olkExplorer.Selection.Count > 0 Then
    If TypeOf (olkExplorer.Selection.Item(1)) Is Outlook.MailItem Then olkMessage = olkExplorer.Selection.Item(1) End If

    End If

    End Sub Private Sub olkMessage_ReplyAll(ByVal Response As Object, ByRef Cancel As Boolean) Handles olkMessage.ReplyAll If MsgBox("Are you sure you want to Reply To All?", _ vbQuestion + vbYesNo, "Verify Reply to All (M&G)") = vbNo Then Cancel = True End If End Sub End Class



    • 編集済み RaginElmo 2013年4月11日 11:42 added some code
    2013年4月11日 11:15