MS Outlook Send Event hooking (1 Viewer)

Mutdogus

Registered User.
Local time
Today, 23:20
Joined
Apr 12, 2005
Messages
48
I've been looking for a way to add code to the send event while in MS Outlook.

http://msdn.microsoft.com/en-us/library/aa168477(office.11).aspx
is an example of how to hook an event in Excel

but I think I may have misunderstood the object model. I'm thinking I need to use MailItem_Send but when I try and test my theory with

Code:
private sub MailItem_Send()

debug.print "Sent!"

end sub

I get nothing. Anyone have any ideas as to what I'm doing wrong?

I'm using MS Outllook 2003. And I am NOT using the Visual Studio Tools for Office.
 

Mutdogus

Registered User.
Local time
Today, 23:20
Joined
Apr 12, 2005
Messages
48
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
End Sub

I found it by accident. This is the correct event.
 

Mutdogus

Registered User.
Local time
Today, 23:20
Joined
Apr 12, 2005
Messages
48
Send Event - Use Word Grammar Checker

My little project that I was trying to figure out here was this.

My company policy has the Word Editor disabled for use in outlook. So in order to use the grammar checking abilities of MS Word, one would have to open a word document, copy the email into word, then run the check, then copy the resutls back into the email. I wanted to do all of this automagically.

Here's my code.


Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim wdApp As Word.Application
    Dim wdDoc As Word.Document
    'Make sure to set a reference to MS Word
    If MsgBox("Would you like to run the MS Word Grammar Checker?", vbYesNo, "Grammar Check?") = vbYes Then
       
    ' Instantiate object variables.
    Set wdApp = New Word.Application
    Set wdDoc = wdApp.Documents.Add

    wdApp.Visible = True
    wdApp.Activate
    
    With wdDoc
        .Range.Text = Item.Body
        .CheckGrammar
    End With
    
    Item.Body = wdDoc.Range.Text
    ' Destroy object variables.
    wdDoc.Close (wdDoNotSaveChanges)
    Set wdDoc = Nothing
    wdApp.Quit
    Set wdApp = Nothing
    End If

End Sub
 
Last edited:

Users who are viewing this thread

Top Bottom