BobBridges
Active Member
Occasionally I get the ambition to set up something in Outlook that intercepts an event. I've tried it various ways, and so far I haven't gotten Outlook to notice my efforts: When I open an email, or send one, it just opens it or sends it without running or apparently even noticing the routines I wrote.
My latest effort involves trying to intercept the Send action. According to what I read at https://learn.microsoft.com/en-us/office/vba/api/outlook.application.itemsend, I tried creating the following code in a class module:
This is in a class module named EnableEvents. Then in a code module I executed a program by the same name:
So the EnableEvents class exists, and ool is now an object variable pointing to the Outlook.Application property. When I send an email, I expect the ool_ItemSend method to display a MsgBox; instead it apparently is never run at all.
I know that event procedures are notoriously picky about the syntax, so I suspect I've changed something that's important. But I don't know what. Has anyone here ever got Outlook events working at all? It needn't be for the same purpose; if you got any Outlook event to work, and can show me what I'm doing wrong with ItemSend, I expect I can do the rest.
My latest effort involves trying to intercept the Send action. According to what I read at https://learn.microsoft.com/en-us/office/vba/api/outlook.application.itemsend, I tried creating the following code in a class module:
Code:
Public WithEvents ool As Outlook.Application
Private Sub ool_ItemSend(ByVal oeml As Object, bCan As Boolean)
MsgBox "ItemSend!"
End Sub
Sub Class_Initialize()
Set ool = Outlook.Application
End Sub
Code:
Sub EnableEvents()
Set oee = New EnableEvents
End Sub
I know that event procedures are notoriously picky about the syntax, so I suspect I've changed something that's important. But I don't know what. Has anyone here ever got Outlook events working at all? It needn't be for the same purpose; if you got any Outlook event to work, and can show me what I'm doing wrong with ItemSend, I expect I can do the rest.