Office 2003 Addin using Visual Studio Add-in (Extensibility) Project
A while back I had to write an add-in to Microsoft Office 2003 for a client and ran into numerous issues during both the development and the deployment of the add-in. Thought I should post it here in hopes that someone may find it useful.
I use Visual Studio 2005 Standard (I know, I know Visual Studio 2008 is out but I develop Pro/Toolkit and SolidWorks API applications too and am not sure if the upgrade is a simple recompile and link, so have not upgraded.), so in order to develop Microsoft Office 2003 Add-ins I had two options:
- Use the Visual Studio Add-in Template under the "Extensibility" Project Type.
- Use Visual Studio 2005 Tools for Microsoft Office 2003 (VSTO)
- Using Visual Studio Add-in Template
- DEVELOPMENT: Writing code for the add-in gets very clunky. The following is a sample excerpt:
using Microsoft.Office.Core;
using nsWord = Microsoft.Office.Interop.Word;
nsWord.ApplicationClass office_app;
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
applicationObject = application;
addInInstance = addInInst;
if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}
/// which office app is "application"
///
if (application is nsWord.Application)
{
office_app = (nsWord.ApplicationClass)application;
//if (logger.IsInfoEnabled) { logger.Info("host app is Word"); }
}
}
As can be seen from the last few lines, to determine the Office Application that the add-in is loaded in is an equivalence test (using if-else or switch-case or some similar). I know this is not a good solution, but I don't have anything better (if someone has a better suggestion I would really appreciate the tip.
Even if I got beyond that I am still casting the 'object application' to 'Microsoft.Office.Interop.Word'. I guess I could have used inheritance to pass 'application' to a sub-class that would deal with the specific Office Application, but I was surprised to find that you could not simply query for the Office App Type. - DEPLOYMENT: Deploying the Shared Add-in requires a bunch of updates from Microsoft that have to be applied to the target PC:
- Microsoft .NET Framework (I personally installed 2.0 though latest versions should also work)
- KB 908002 (http://support.microsoft.com/
kb/908002) - Download and execute the EXE file. The EXE download actually contains 3 files all of which has to be applied to the target system in the following order: - lockbackRegKey.msi
- office2003-kb907417sfxcab-ENU.
exe
- extensibilityMSM.msi
- Office 2003 Primary Interop Assemblies (http://www.microsoft.com/
downloads/details.aspx? FamilyId=3C9A983A-AC14-4125- 8BA0-D36D67E0F4AD&displaylang= en) - The download (an EXE file) contains an MSI file that has to be run on target system.
As far as I can tell KB 908002 and the Office 2003 Primary Interop Assemblies cannot be uninstalled.
Acknowledgements:
No problem Anish. Do let me know if you prefer more such articles. Nice blog yourself by the way.
ReplyDeleteshri Ganeshram Iyer..it is really very nice blog.. i m doing my dessartation work of masters degree, in which i probebly use pro/toolkit if i succeed.
ReplyDeleteyour articals r very useful 2 me as there is very little help is available on this topic.so please keep up the great work..hope u will came up with small application/project using toolkit.........thx again.
Sandip frm India
Thanks Sandip
ReplyDeleteI am not sure if you have seen my articles: Pro/Toolkit + Visual C++ HowTo - I provide a ZIP that has the source code to create a Pro/Toolkit DLL.
http://ossandcad.blogspot.com/2008/03/howto-example-protoolkit-application.html.
If you go through my blog archive for 2008, you will find many Pro/Toolkit related posts.