WynApse Home Page
Home    Blog    About    Contact       
Latest Article:

My Tags:
My Sponsors:

Lifetime Member:

First Word Addin with Add-in Express

Here's one that's a tad off the beaten track around these parts... how about some posts about Office Add-ins? ... or more spcifically Word Add-ins? Or drilling right down into the crux of the post, how about Add-in Express?

Add-in Express

If you find yourself in need of an Office Add-in, and want to get a real leg up on the process, you should check out Add-in Express. I've had the opportunity to be giving their Microsoft Office and .NET package a dance and figured I'd report on it.

Be aware that this is a discussion of this product based upon my current use and nothing more. I've played around with some Excel samples, but primarily have focused on Word. I also have not had an opportunity to test a version of Word other than 2010, but based on everything else that's going on, I have no doubt what I've built will work on all versions I selected when I started the project (more about that later).

What it's not

Prior to running Add-In Express for the first time, I had expected somewhat of a 4GL. If you follow any of the tutorial videos, you may get a slight impression of that as well. As it turns out, once things were setup and the TaskPane was running, I've been spending all my time with WPF and Telerik controls, and having very little at all to do with Word or Office, and wow... that's what I was shooting for!

What it is

Add-In Express is a product that loads into Visual Studio and allows you to build Office COM Add-Ins easier than using standard VSTO. If you've had a need for an add-in and shied away from it because of VSTO, you can get over that right now.

I wanted to give Add-in Express a good shakedown, so here's the shopping list of what I have running in a TaskPane:

  • Add-in Express (duh)
  • Prism
  • Unity
  • Telerik WPF controls
  • and I'm talking to a WCF service
And rest-assured I am NOT going to be discussing all that in this post!

Cranking up a new Project

1) When you create a new Office COM Add-in based on Add-In Express, you'll pick "Other Project Types" from your Installed Templates, then select "Extensibility" and find these choices:

2) I'm going to choose "ADX COM Add-In" for this getting-started post.

You pick a location and give your project a name just like every other new project.

Pressing "OK" brings up this Add-in Express dialog:

Two very cool things to note: First, all the choices of Project available, and second the "Minimum" supported Office version. That's not "which" version... it's the Minimum... So having chosen Office 2000 as in the image above, my Add-in will work for any version from 2000 through 2013!

3) After making your selection on the dialog shown above, you'll get this dialog:

4) from which you get to select which Office Applications you're going to program for. This rats around and finds what you have installed, so if your mileage may vary on what you see in this dialog. As I said before, I'm only interested in Word at this point, so that's what I selected.

5) But wait, there's more... the next dialog lets you browse for a Strong name key file if you have one, or it will generate one for you:

6) And then you're done, and can press "Finish".

Add-in Express will generate the project and underlying soup to make this all work, and you end up with a Solution Explorer that looks something like this:

You can compile at this point, but if you try running it, nothing will show up because you haven't added anything to display... that's next :)

Wiring up a Hello Add-in

Ignoring, for now, the addition of a RibbonBar tab, I'm going to put up a minimal TaskPane, but I'm going to do it in WPF so I can fall back on my C#/XAML skills.

7) To get the flow of the process correct, I'm going to add the WPF User Control first, so right-click the project, select "Add", then "New Item" as shown below.

This is all standard Visual Studio stuff, but I'll show it for completeness.

8) We want to add a WPF User Control as shown in the next screenshot, and I named mine WPFUserControl1

9) This will add a bare-bones WPF control with an empty Grid. For this Demo, all I'm going to do is add a TextBlock inside that grid as shown in the following screenshot:

10) Now right-click on the project again, select "Add", and this time selected "User Control":

I accepted the default "UserControl1" name to go along with my WPFUserControl1 I built above.

11) Now we add the bit of magic that makes this all work... In the Toolbox, find the "WPF Interoperability" section, and open it as shown:

12) Drag that "ElementHost" object over onto the "UserControl1" we just created in step 10. When you drop it, you will see this in the design screen:

13) Click the small configure button to bring up the screen shown below, and select "Dock in Parent Control":

14) Now before the next step, do a rebuild all. I've read that this works, but I've never seen it happen, but I'll mention it here. Supposedly if you rebuild, the system will know about your WPF control, and you can select it into the UserControl. To give this a shot, once again click the configure button, and click the dropdown box to "Select Hosted Content" as shown:

If this works for you, I'm not certain of the process. I'm assuming you would be able to select the WPFUserControl1 and go on. As I said, this has never worked for me.

14b) If step 14 didn't work for you, to get the control selected into the host, right-click the white area of the designer away from the control, and select "View Code":

Inside the UserControl1() method add the two lines of code shown below to instantiate the WPFUserControl1 and select it into elementHost1:

16) One last step before we can test this is to select the "AddinModule.cs [Design]" tab, or if it's no longer showing, click the AddinModule.cs in the solution explorer to get it on-screen. In the top part of the designer window, right-click and select "Properties". I've had this not give me the properties I needed until I clicked again on the lower half of the design screen, but maybe that was my setup... just letting you know :)

When you have Properties showing, click "TaskPanes" which is, in my Properties, the bottom choice:

17) Click the ellipses button to bring up an empty ADXTaskPane Collection Editor box, and click the "Add" button as shown:

18) On the right-hand side, click "ControlProgID" to show the dropdown arrow:

19) Click the dropdown and you will see one entry, the fully-qualified name of our UserControl1. Select that, and press Close:

20) To run, you first have to register your project, so after rebuilding to make sure there's nothing wrong, go back to the build menu, and select "Register ADX Project":

You'll get a confirmation box that it registered:

21) Now launch Word, and see your WPF TaskPane running inside as shown:

22) Go get yourself a congratulatory beverage of choice, and bask in the beauty of the TaskPane you've just created and can program without having to get down and dirty with VSTO.

Next Time

Next time we'll do a bit of customization of this control and add another, plus show how to show and hide them and save the user's selection for the next time they run.

Enjoy what you program in, and

Stay in the 'Light!

Copyright © 2006-2022, WynApse