Inspector.WordEditor always returns null

  • Thread starter Peter O'Dowd \(MVP\)
  • Start date
P

Peter O'Dowd \(MVP\)

I'm writing an Outlook Add-In, using C# in VS 2005. ( not using VSTO) .
The Add-In uses the shim provided my Microsoft for developing add-ins.

Here's a snippet of the code...
Outlook.Inspector oi = MailItem.GetInspector;

Microsoft.Office.Interop.Word.Document doc =
(Microsoft.Office.Interop.Word.Document)oi.WordEditor;

I need to position the cursor at a certain location in a part of message
body I populate when the mail item is created, hence why I need access to
the WordEditor

Any help greatly appreciated...
Thanks
 
K

Ken Slovak - [MVP - Outlook]

Hi Peter,

Outlook version you want to work with?

In Outlook 2007 I've found that until the first Inspector.Activate() event
fires that IsWordMail() and WordEditor are null. That's especially the case
if you try to get those during NewInspector().
 
P

Peter O'Dowd \(MVP\)

Hi Ken,
Yes it is Outlook 2007. Thanks for the info, I'll investigate :)
Cheers
 
P

Paul T (NJ, USA)

I am having the same problem after the upgrade to 2007 wiht outomation that I
had in place with NewInspector() event... My work-around was the following:

1) Use NewInspector event to set local class variable to the inspector
2) Define the Activate event for the new inspector variable.

Here is my simplified code with the asnwer:

-----

Dim myOlApp As New Outlook.Application
Public WithEvents myOlInspectors As Outlook.Inspectors
Public WithEvents oActiveInsp As Outlook.Inspector

Public Sub Initialize_handler()
Set myOlApp = Application
Set myOlInspectors = myOlApp.Inspectors
End Sub

Private Sub oActiveInsp_Activate()

' your processing code goes here... wordEditor will be defined now.
' I suggest unsetting oActiveInsp once you're done with it, so that it
does not impact performance everytime you focus on this inspector.

set oActiveInsp = nothing

End Sub


Private Sub myOlInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
Set oActiveInsp = Inspector
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