How to tell if Word is running inside Outlook as email editor.

M

Mel Green

Hey guys,

I've written an addin for Word that loads a new toolbar with a button. It's
fairly simple and works great.

A problem I've run into however is that when Outlook uses Word as its email
editor inside its 'Create New Email' window, Word will load my addin which
will create the toolbar and button inside this window. Since my toolbar and
button have nothing to do with Outlook and serve no purpose there, I'd like
to be able to tell when my addin loads whether or not Word is running inside
Outlook, then I could defer from loading my toolbar.

I've tried doing this by checking the 'UserControl' property of the
WordApplication COM object, which works in that it detects when Word is
opened inside Outlook, in which case I can not create my toolbar. But the
problem with this approach is that if I've opened Outlook before I open Word
regularly, the 'UserControl' property is still set to "false", which causes
my code not to load the toolbar inside Word like it should.

If anyone knows of another method of accomplishing this, or a better way of
using the method I've got, please let me know. I would greatly appreciate any
advise on this subject!

~Mel
 
K

Ken Slovak - [MVP - Outlook]

Use Word.ActiveDocument.EnvelopeVisible. If True it's a mail item and if not
it's a standard Word document.

From the Outlook side we use Outlook.ActiveInspector.WordEditor. If True
it's a WordMail item.
 
M

Mel Green

Thank you Ken,

That method does indeed allow me to determine whether Word is working with
an email inside of Outlook or a regular document. But the accomplishment of
that task has just led me to the realization of a bigger problem.

I've written my addin using ATL/C++ which uses the IDTExtensibility2
implementation. So with the standard 'OnConnection' function that gets called
when Word loads my addin, I can only initialize once until Word is shutdown
and initialized again. This means that when Outlook loads Word and I decide
not to display my toolbar, if I then open Word regularly without closing
Outlook first it won't call my 'OnConnection' again and I won't be able to
load my toolbar in the actual Word window.

This is a different problem than my initial question, and I really
appreaciate the help I've received so far. But if anyone has any advise on
this issue, please let me know.

Thank you again Ken!

~Mel
 
K

Ken Slovak - [MVP - Outlook]

Use the Word.WindowActivate() event for that. The EnvelopeVisible property
can be used to check what window type is being activated.
 
M

Mel Green

Thank you Ken, that seems to be just what I'm looking for!

I'm having a little trouble importing the Word library so that I can put the
sink in place for handling the WindowActive() event, but I don't think that
will be to much of a problem. I'll post back again when everything's ironed
out.

Thank you again for all your help.

~Mel
 

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