How do I link outlook events to Word being used as email editor?

  • Thread starter Michael Bauer [MVP - Outlook]
  • Start date
M

Michael Bauer [MVP - Outlook]

You have to declare the variable for the object that sends the events With
Events. For that you must add a reference to Outlook to your Word project
via Tools/References. Sample:

Private WithEvents m_Mail as Outlook.MailItem

Now you can choose m_Mail in the left combobox (right above the code window)
and then its several events from the right one.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)

Am Tue, 27 Feb 2007 09:05:05 -0800 schrieb Graybane:
 
G

Graybane

Mike, Thanks for your reply. I have done everything you have stated and the
event is not firing. I have a structure wrong. I have included the code
structures that I am using. I should say that everything is tied to
Normal.dot and Document1 has a reference to Normal.
Word Mail editor with Outlook 11.0 reference set and Normal.dot
being picked up

Created Class Module MyClass
Option Explicit

Public WithEvents OutlookMail As Outlook.Application
Public WithEvents OutlookMailNS As NameSpace
Public WithEvents OutlookMailInspector As Outlook.Inspectors
Public WithEvents OutlookMailItem As Outlook.MailItem

Public Sub OutlookMailInspector_NewInspector(ByVal Inspector As
Outlook.Inspector)

Dim MySubject As String
MySubject = "***Alert*** Reports Error"


Set OutlookMail = CreateObject("Outlook.Application")
Set OutlookMailNS = OutlookMail.GetNamespace("MAPI")
Set OutlookMailInspector = OutlookMail.Inspectors
Set OutlookMailItem = OutlookMail.CreateItem(OlItemType.olMailItem)

If OutlookMailItem.Subject = MySubject Then
'Some tasks..........
End If
End Sub

Created Module Module1
Option Explicit

Public MC As New MyClass
Sub Register_Event_Handler()
Set MC.OutlookMailInspector = CreateObject("Outlook.Inspectors")
Set MC.OutlookMail = CreateObject("Outlook.Application")
Set MC.OutlookMailNS = QC.OutlookMail.GetNamespace("MAPI")
Set MC.OutlookMailInspector = Outlook.Inspectors
Set MC.OutlookMailItem = QC.OutlookMail.ActiveInspector.CurrentItem
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top