Click here to Skip to main content
6,822,613 members and growing! (21,526 online)
Email Password   helpLost your password?
General Programming » Macros and Add-ins » General     Beginner

Managed Word Add-in: The Initial Design

By Pavan K Kulkarni

This article looks at all the options available and trades-off each of them for developing a word add-in. It aims to help the developer choose the best option according to the requirements
C++, VB, C#2.0.NET2.0, WinXP, Win2003, COM, VS2005, Dev
Posted:22 Nov 2006
Views:21,873
Bookmarked:9 times
Unedited contribution
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
8 votes for this article.
Popularity: 1.40 Rating: 1.55 out of 5
5 votes, 62.5%
1

2
1 vote, 12.5%
3
1 vote, 12.5%
4
1 vote, 12.5%
5

Managed Word Add-in: The Initial Design

The Options
Following are the options to write a managed word add-in:

  1. VSTO:
    VSTO is a great tool. Many complicated tasks like shimming are taken care inherently by VSTO (Orcas). VSTO word add-ins are scoped to document level and template level, but not application level.
    1. Word Document:
      VSTO provides �Word Document� template (in VS) to create a word add-in. The code that is written here is more or less like VBA with added advantage of full access to Framework Class Library (FCL). This code is associated only with this particular document and doesn�t run for any other word document.
    2. Word Template:
      VSTO provides one more template, �Word Template�. This provides more generic solution than the previous option. The basic idea is to write all the code in this template and place this template in the STARTUP folder of Office. This results in loading of this template for each document that is opened/created and thus, the code runs for the document.

The base line here is to use VSTO when the solution (add-in) needs to be scoped at the document level or the template level. Though there is more flexibility at the template-level add-in there are few things that this approach can�t achieve, like loading of this template selectively for some documents.

  1. Shared Add-in:
    If the word add-in needs to be running at application level, use shared add-in approach. �Shared Add-in� is a template that is provided by VS and doesn�t require VSTO to be installed. Add-in created using this approach inherits from IDTExtensibility2 interface. This is the crux of this approach.

Shared Add-ins run on each of the documents that is opened or created on the machine. This is the scoring point of shared add-in over the VSTO approach, though there are few things that need to be taken care by the developer and are cumbersome (the trade-off).

 

The Winner

As a thumb rule in any design exercise, there are no winners. Same applies here. 

Use VSTO when,

  • As already mentioned, your solution doesn�t need to be at an application level and doesn�t need higher flexibility (like running code while word application connects to the add-in or finishes the connection etc).
  • You need added advantages of managing shimming inherently (Shimming is very important and a painful process, esp. if the developer doesn�t have knowledge of C++). Not only shimming but also many small things that need to be managed by the dev in shared add-in approach are built-in here, like adding a transparent icon to a command bar button.
  • In many of the cases the �Word Template� approach does the trick, unless one wants to meddle with the template itself. For example, if on a conditional check you want to remove the template that you have your code in i.e. you don�t want the add-in to run, you can�t delete the template as it is present in STARTUP folder. This kind of flexibility is available only in shared add-in approach.
  • You don�t want to worry about Office version compatibility. VSTO supports all Office versions from and after Office 2003. So, the developer need not worry about making the add-in compatible to all the versions.

Use Shared add-in approach if

  • Your solution needs to be at an application level i.e. you the code to run on each of the documents.
  • You need more flexibility and access to the startup process of both add-in and Word.
  • You can make your add-in work on any Office version from and after Office 2000 (There was no add-in concept before that), though it requires additional work. You can take advantage of
  • But be aware that there can be many hiccups before the solution can be deployed successfully on end-user machines, esp. if they are clean machines.
    • Hiccups like shimming, not being able to remove the toolbar/menu that is added, adding transparent icons to command bar buttons and menu items, on the development side.
    • On debugging side, you need to attach WINWORD.EXE to VS for being able to debug. But by the time you start Word and come to attach it into VS; all your startup code would have been executed.
    • On the deployment side, all the updates need to be installed before the add-in is run or the add-in might get disabled. And the bad news is that the reason for it being disabled will never be communicated to the user.

But there are solutions for each of these issues and are implementable though not very easy.

 

On the whole, VSTO solution is very specific while shared add-in approach is more generic. Eventually, the decision depends on your requirements.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Pavan K Kulkarni


Member

Occupation: Software Developer (Senior)
Location: India India

Other popular Macros and Add-ins articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 7 of 7 (Total in Forum: 7) (Refresh)FirstPrevNext
GeneralMy vote of 1 PinmemberMember 37483522:04 2 Jul '09  
GeneralVSTO Add In for Word Pinmemberkokatnur22:27 7 Jun '07  
GeneralAdding an Actions Pane in word 2003 PinmemberJ.Ravi5:12 23 May '07  
GeneralRe: Adding an Actions Pane in word 2003 PinmemberPavan K Kulkarni4:56 28 May '07  
Generalshared add in + vsto Pinmembernitstheone20:19 25 Mar '07  
GeneralRe: shared add in + vsto PinmemberPavan K Kulkarni22:13 25 Mar '07  
GeneralRe: shared add in + vsto Pinmembernitstheone22:57 25 Mar '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

PermaLink | Privacy | Terms of Use
Last Updated: 22 Nov 2006
Editor:
Copyright 2006 by Pavan K Kulkarni
Everything else Copyright © CodeProject, 1999-2010
Web17 | Advertise on the Code Project