Tips and tricks for Office add-ins:
.NET Framework, PIA, Office extensions

Add-in Express™
for Microsoft® Office and .net

Add-in Express Home > Add-in Express .NET > Online Guide > Tips and tricks

Tips and tricks for building Office add-ins

Building COM add-ins in Visual Studio .NET - Flash video

You might have an impression that building add-ins is a very simple task. Please don't get too enthusiastic. Sure, Add-in Express .NET makes embedding your code to Microsoft Office applications very simple, but you are to write the application code yourself, and we guess it would be something more intricate than a single call of MessageBox. On this page you will find some tips and tricks related to using .NET Framework versions, version-independent PIAs, creating multiple Office extensions, etc.

.NET Framework 1.1 and 2.0 installed on the development PC

In a mixed .NET Framework environment, you may need to use the Host Configuration command of an ADX Module. This command [creates and] changes the configuration file for your host application. The examples of configuration file names are outlook.exe.config and excel.exe.config. The file is located in C:\Program Files\Microsoft Office\OFFICE11.

.NET Framework 3.0 and 3.5

Those .NET Framework versions are just add-ons for .NET Framework 2.0. Note that .NET Framework 3.0 and higher can't be installed on Windows 2000; if you need to work on that OS, you have to switch your project to .NET Framework 2.0. See your project properties.

Office extensions based on different .NET Framework versions

Neither Office nor any other application can load several .NET Framework versions simultaneously. This is the reason why an Office extension based on .NET Framework 1.1 may cause other Office extensions based on .NET Framework 2.0 (also 3.0 and 3.5) to work incorrectly, and vice versa. Always check the log file (see Where's My Log File) for .NET Framework versions. If you spotted such an extension, then you need either to turn it off, or use the same .NET Framework version in your project.

What is PIA?

PIA (Primary Interop Assembly) provides the compiler with early-binding information on host application objects, their properties and methods. In Visual Basic 6 terms, PIAs correspond to references you set using the Project / References dialog. Office applications are almost 100% backward compatible and you can use a PIA from an earlier Office version to work with a newer one. Say, you can develop your add-in using Outlook 2000 PIA and it will work with Outlook 2007. Note, in this case, you can access Outlook 2007 features using late binding (see the InvokeMember method in MSDN). Obviously, you cannot expect the add-in developed with Outlook 2007 PIA to work with Outlook 2000: say Outlook 2000 (as well as Outlook XP and Outlook 2003) doesn't have the Explorer.Search event specified in Outlook 2007 PIA. See also a post on Add-in Express blog: Microsoft Office PIAs in your COM add-in projects.

Version-neutral interop assemblies

Add-in Express includes version-neutral PIAs for all Office applications: just check the Version-neutral PIAs checkbox in the Add-in Express Project Wizard. This will add interop assemblies for the earliest versions of your add-in's host applications. Say, if you host your add-in in Outlook, this will be Outlook 2000 PIA. And for InfoPath, this will be InfoPath 2007 PIA.

Getting help with COM objects, properties and methods

To get assistance with host applications’ objects, their properties and methods as well as help info, use the Object Browser. Go to the VBA environment (in the host application, choose menu Tools / Macro / Visual Basic Editor or just press Alt+F11), press F2, select the host application (also Office and MSForms) in the topmost combo and/or specify a search string in the search combo. Select a class/property/method and press F1 to get the help topic that relates to the object.

Developing multiple Office extensions in the same project

If you develop several Office extensions in one assembly, you should understand that Office loads your assembly several times: say, if you have a COM add-in, an XLL add-in and an RTD server in the same assembly, the assembly will be loaded three times. Add-in Express loads all such extensions into the same AppDomain. The only exception is the Excel Automation Add-in, which is loaded to the default AppDomain. You can load your Excel Automation add-in into the same AppDomain as your COM add-in by calling any of its functions via ExcelApp.Evaluate. Note that COM add-ins, Excel Automation add-ins, and RTD servers can be installed either for the current user only or for all users on the PC. Smart Tags can be installed for all users only. XLL add-ins can be installed for the current user only.

Always use the actual version of the Add-in Express Loader

Since the code of the loader is frequently changed, you must use its latest version. Whenever you install a new Add-in Express version, copy adxloader.dll located in {Add-in Express install folder}\Redistributables to the Loader folder of you project. For XLL add-ins, you must also rename it to adxloader.{XLL add-in project name}.dll.

XP styles in your forms

Just call System.Windows.Forms.Application.EnableVisualStyles() in your add-in module.

Wait-a-little

Some things aren't possible right at the moment; say, you can't close the inspector of an Outlook item in the Send event of that item. A widespread approach is to use a timer. Add-in Express provides a way to do this by using the SendMessage method and OnSendMessage event; when you call SendMessage, it posts the Windows message that you specified in the methods' parameters and the execution continues. When Windows delivers this message to an internal window, Add-in Express raises the OnSendMessage event. Make sure that you filter incoming messages; there will be quite a lot of them.

The actual names of the SendMessage method and OnSendMessage event are listed below:

SendMessage

  • ADXAddinModule.SendMessage
  • ADXOlForm.ADXPostMessage
  • ADXExcelTaskPane.ADXPostMessage
  • ADXWordTaskPane.ADXPostMessage
  • ADXPowerPointTaskPane.ADXPostMessage

OnSendMessage

  • ADXAddinModule.OnSendMessage
  • ADXOlForm.ADXPostMessageReceived
  • ADXExcelTaskPane.ADXPostMessageReceived
  • ADXWordTaskPane.ADXPostMessageReceived
  • ADXPowerPointTaskPane.ADXPostMessageReceived

Note. If you didn't find the answer to your questions on this page, please see the HOWTOs section:

Creating setup projects manually <<

>> COM add-in tips

Back to Add-in Express .NET homepage

Have any questions? Ask us right now!