yoey2007
asked on
How do I capture the Outlook ItemSend event from a VB.Net 2005 plug-in
I need to write a plug-in for Outlook 2003 using VB.Net 2005 that captures the ItemSend event. Using the wizard I have created the attached class but having trouble working out how to create the ItemSend event handler.
What code do I use to hook into the event? What do I need to reference so intellisense displays the events etc for the Outlook object?
What code do I use to hook into the event? What do I need to reference so intellisense displays the events etc for the Outlook object?
imports Extensibility
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports Microsoft.Office.Interop.Outlook
<GuidAttribute("8485231B-D0A4-4A14-9FBE-52894D3CA7AF"), ProgIdAttribute("MyTestAddin.Connect")> _
Public Class Connect
Implements Extensibility.IDTExtensibility2
Private WithEvents applicationObject As Object
Private addInInstance As Object
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub
Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
MessageBox.Show("Addin Started")
End Sub
Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
End Sub
Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
applicationObject = application
addInInstance = addInInst
End Sub
Public Sub ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles me.applicationObject.outlookevents.itemsend
MessageBox.Show("Email Sent")
End Sub
End Class
ASKER
hi angelll,
What reference do I need to make in my project for the ... As Outlook.Application to work?
I currently get an error "type Outlook.Application is not defined"
What reference do I need to make in my project for the ... As Outlook.Application to work?
I currently get an error "type Outlook.Application is not defined"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help angelll
I added a reference to "Microsoft Outlook 11.0 Object Library" as I'm using Outlook 2003 but was still getting the same error.
I changed the following line
Imports Microsoft.Office.Interop.O utlook
to
Imports Outlook = Microsoft.Office.Interop.O utlook
and it all works.
I added a reference to "Microsoft Outlook 11.0 Object Library" as I'm using Outlook 2003 but was still getting the same error.
I changed the following line
Imports Microsoft.Office.Interop.O
to
Imports Outlook = Microsoft.Office.Interop.O
and it all works.
AFAIK:
Private WithEvents applicationObject As Object
needs to be
Private WithEvents applicationObject As Outlook.Application
and
Public Sub ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles me.applicationObject.outlo
should be:
Private Sub ItemSend(ByVal Item As Object, ByRef Cancel As
Boolean) Handles applicationObject .ItemSend
hope this helps...