Delen via


Office 2010 PIA installer does not install the Word PIA if only Outlook 2010 is installed

A few days ago I ran into an issue where the customer had written an add-in for Outlook 2010 and was working with the WordEditor property of the Inspector. The add-in was to be deployed to machines which had ONLY Outlook 2010 installed. Would this work?

Yes, It should! In this case we got an exception that says that the file Microsoft.Office.Interop.Word.dll could not be found. Digging deeper into the issue we found out that it was an issue with the PIA Installer for Office 2010. The Installed did not install the Microsoft.Office.Interop.Word.dll if Word was not installed on the machine.

Is that what the installer should be doing? NO. The Office 2007 PIA installed worked just fine and even if only Outlook was installed on the machine it installed the PIA for Outlook as well as for Word. Yes, this is an issue with the Office 2010 PIA installer and will be fixed!

Now what? What are my options to solve the problem?

The only two that I see are:

1) Distribute the Microsoft.Office.Interop.Word.dll along with the setup: This is not something that we recommend. It is recommended to always install the PIA using the Official Installer. Now since the installed is not doing it’s job, look at option 2

2) Use Late Binding: I was able to get the add-in to work without the word PIA. Writing late binding code could be a pain but it is the only other solution that worked!

In the sample code below we are setting the subject and the body of the message to “This text was set by the add-in”. Notice the code to insert the text “This text was set by the add-in” into the body of the message late binding and WordEditor object.

 if (activeInspector.CurrentItem is Outlook.MailItem)
{
    Outlook.MailItem mail = ((Outlook.MailItem)activeInspector.CurrentItem);
    mail.Subject = "This text was set by the add-in";

    if (activeInspector.EditorType == Outlook.OlEditorType.olEditorWord)
    {
        object wordDoc = activeInspector.WordEditor;
        object wordWin = null;

        IEnumerator wordDocEnumerator = null;

        if (null != wordDoc)
        {
            object oWindows = wordDoc.GetType().InvokeMember("Windows", System.Reflection.BindingFlags.GetProperty, null, wordDoc, null);

            if (null != oWindows)
            {
                wordDocEnumerator = (IEnumerator)oWindows.GetType().InvokeMember("GetEnumerator", System.Reflection.BindingFlags.InvokeMethod, null, oWindows, null);
            }

            if (wordDocEnumerator.MoveNext())
            {
                wordWin = wordDocEnumerator.Current;

                object oSelection = wordWin.GetType().InvokeMember("Selection", System.Reflection.BindingFlags.GetProperty, null, wordWin, null);
                oSelection.GetType().InvokeMember("TypeText", System.Reflection.BindingFlags.InvokeMethod, null, oSelection, new object[] { "This text was set by the add-in" });
            }
            else
            {
                MessageBox.Show("Could not find the word editor window to insert the text body into");
            }
        }
    }
    else
    {
        MessageBox.Show("The editor type was not word, so the add-in cannot continue");
    }
}

Some good articles on binding

I will let you know when the issue with the Office 2010 PIA installed is fixed. Enjoy!