C# inserting word document with formatting into outlook message

  • Thread starter Thread starter Huginson
  • Start date Start date
H

Huginson

Hi

I have been trying for days now to create a solution for this. The problem
is i have found some code examples on the web, but none of them has worked so
far. Maybe i'm missing a reference when trying them i don't know (altho i
have tried most references ). I have tried myself and also used msdn trying
examples, tho it seems to me they put out examples for everything in outlook
but the basic function of the program like working with mail messages and
interacting Oulook with other office products. Maybe i lack some basic
understanding, however i tried to read everything i could come across for
this.

This is the scenario:
I am using Visual Studio 2008
Office 2007
I am making an Outlook ribbon where the user on editing in a oulook message,
pick a word document from a dropdown in the Outlook ribbon and then i want
the word document to be inserted where the user has hers/his cursor before
going to the dropdown menu.

I have made the same function for word: there i used this code and it works
just as i want to

Word.Range currentRange = Globals.ThisAddIn.Application.Selection.Range;

object missing = System.Type.Missing;

currentRange.InsertFile(workindirectory +
"\\" + fname, ref missing, ref missing, ref missing, ref missing);


However this does not work for Oulook.

On my search i have encountered alot of people trying to find out the same
thing. Seems to me alot of folks want to use word documents for some kind of
standard template they can put into their email messages when replying to
customers etc. However most examples i have found use fully automated
answers. With office Ribbon that is not what you would normally want. The
ribbon is there for a person to click :) Besides you don't want to create a
new mail. You would want the word document to be inserted into the mail the
user is working on.

The closest i have come in my search are the Inspector.WordEditor; in the
documentation it says this should put a word document at the users cursor.
I have yet to find a C# example of this that actually works. And the
documentation i have found for WordEditor is...well not very friendly :)

Anyone that can help me here. Like i said i tried for days with 10-12 each
day searching for it and im getting a bit frustrated.

Thanks
 
In Outlook 2007 there is only the Word editor and Inspector.WordEditor is a
Word Document object. It's a weak object reference for the Inspector that
you get in the Inspectors.NewInspector() event, so you are best off
instantiating an Inspector object in that event handler and subscribing to
the Inspector.Activate() event for the Inspector. In the first Activate()
event you can get WordEditor and cast it to a Word.Document object. Pretty
simple really.

There are C# examples for at least getting to WordEditor lots of places, for
example at www.outlookcode.com. I have VS 2005 templates, including C#, that
show how to handle up to the Inspector.Activate() event, from there all you
need it this before you descend into the Word object model:

Word.Document doc = (Word.Document)insp.WordEditor;
 
Back
Top