Accessing a Word Document from my Outlook Addin

Add-in Express™ Support Service
That's what is more important than anything else

Accessing a Word Document from my Outlook Addin
 
DavidT543


Guest


Hi,

I have an Outlook add-in that is coming along nicely thanks to Addin express.

I need to access Word to open a word document and retrieve the email object of the document before using it in my addin. I have done this in VB6 in previous incarnations of my app, but now I want to do it in VB.net using Addin express - hopefully in a way which gives me neutrality of installed Word version. I don't need a word add-in (although if thats what I need to do then I will do that) as the user never needs to touch word. I'm just using word to create an email template programatically.

Is there a word object I could/should use.

My code was something like (i've removed error checking stuff):

Set oWord = GetObject(, "Word.Application")
If oWord Is Nothing Then Set oWord = CreateObject("Word.Application")
Set oWordDoc = oWord.Documents.Add(myFileName)
Set wItem = oWordDoc.MailEnvelope.Item
wItem.Save
myID = wItem.entryID
oWordDoc.Close SaveChanges:=wdDoNotSaveChanges
If blWeOpenedWord Then oWord.Quit
Set oWord = Nothing
Set oItem = ObjNS.GetItemFromID(wItem.entryID)
Posted 10 Sep, 2010 14:28:11 Top
Andrei Smolin


Add-in Express team


Posts: 18794
Joined: 2006-05-11
Hi David,

Note that Word.Document.MailEnvelope was introduced in Word 2002. Accordingly, that code will work in Word XP and subsequent Word versions. Because that property is missing in the version-neutral Word interop (which is an interop for Word 2000), you have two ways:
- use the primary interop for any Word version (2002-2010);
- use late binding, see System.Type.InvokeMember in MSDN; also there are many samples on this forum

I also recommend reading http://www.add-in-express.com/creating-addins-blog/2010/03/16/interop-assemblies-late-binding/


Andrei Smolin
Add-in Express Team Leader
Posted 13 Sep, 2010 03:49:40 Top
DavidT543


Guest


Hi Andrei,

thank you for your response.

I haven't had to make a reference to Word at all yet. In fact my Add-in has no references to word at all. It is aimed purely at Outlook. I juts need to open word quickly, get the email envelope and close it again.

Where can I find the version-neutral Word interop so that I can make a reference to it? I can't find where Add-in Express keeps it. Or should I be setting a parameter in via the Add-in interface?

regards

David
Posted 13 Sep, 2010 11:46:48 Top
Andrei Smolin


Add-in Express team


Posts: 18794
Joined: 2006-05-11
Hi David,

If you use Add-in Express 2010, see Interop.Word.dll in {Add-in Express}\Redistributables\Interop Assemblies\VersionNeutral\ on your PC. In previous Add-in Express versions, that file is located in {Add-in Express}\Interop Assemblies\.


Andrei Smolin
Add-in Express Team Leader
Posted 13 Sep, 2010 11:57:24 Top
DavidT543


Guest


Hi Andrei,

thank you for your response. I love you guys. Your product support is absolutely the best I have experienced - quick and accurate. (and you can quote me on that)

I got this to work for me by making a reference to the Add-in express version neutral assembly (as you suggested), and then using the following code:

Dim oMEnv As Object = oWordDoc.GetType().InvokeMember("MailEnvelope", _ Reflection.BindingFlags.GetProperty, Nothing, oWordDoc, Nothing)
wItem = oMEnv.Item

The rest was almost the same as for VB6

Thanks for a great product and great support.


regards

David
Posted 13 Sep, 2010 12:52:05 Top
Andrei Smolin


Add-in Express team


Posts: 18794
Joined: 2006-05-11
David, thank you very much and dood luck with your project!


Andrei Smolin
Add-in Express Team Leader
Posted 14 Sep, 2010 08:18:08 Top