Script Smart

Microsoft you are entering or viewing, and Office XP introduces a powerful new feature, smart tags, which allows Office applications and Microsoft Internet Explorer to analyze the information that provide links to relevant information about the content. This is great for when you're writing reports or spreadsheets, and you want to be able to look up some information quickly. A good example of how Office uses smart tags is e-mail addresses. When you type in a person's name, Office will look that up in your Outlook contacts database, and if the person exists, then the smart tag enables you to click on the user name and select an option from a context menu. In this case, you can send the person an e-mail, organize a meeting, open the contact, or even insert the address of the user. Luckily, the developers of smart tags realized that developers need a way to write new smart tags, and so they provided a Smart Tag SDK. In this article I'll take a look at the Smart Tag SDK and how you can use it from a scripting perspective.

How Do Smart Tags Work?

In order to understand how to use smart tags, it's important to know how the system works. Smart tags can do two things: 1) recognize content that is sent to them, and 2) perform actions based on the content. The implementation of the "recognizer" and action is provided by a series of COM objects. Microsoft Office ships with a number of recognizers and actions by default, such as the name recognizer and action I used in my earlier example. When Word loads, it checks to see what recognizer or action add-ins are available on the system, and then ensures that these are loaded so when you start typing, any context is passed into the add-ins. The Smart Tags SDK (You can get the SDK from Microsoft Office XP Smart Tag SDK) has a good architectural diagram that shows how things work:

The components that respond to actions and recognition have to implement a particular COM interface, which would appear to rule out the use of script. Luckily, however, the smart tags solution supports a mechanism to create a smart tag via XML, which can then link to a server. This means that you can use this to link through to script running in an ASP page to do much of the work.

Smart Tag Lists

Smart tag lists provide a simple XML-based mechanism for defining a set of terms that smart tags will recognize without having to go to the trouble of implementing a complete COM component. All you need to do is create a list of terms in XML, and then create a list of actions to show whenever a term from the list is encountered. The Smart Tag list plug-in loads the XML definition whenever Microsoft Word, Microsoft Excel, or IE are loaded, and ensures that whenever a term from the list is encountered in a document, a menu containing all the actions is shown. The great thing about this is that the actions can link to ASP pages with context about the term.

To illustrate how you can use script to take advantage of this, I've built a Microsoft VBScript syntax helper for The list of terms is a list of keywords, functions, and statements for VBScript, and there are two actions presented to the user whenever they use the smart tag in Word, Excel, or IE: "Get Help from" and " is cool." The first action navigates to an ASP page, getref.asp, which will show all the relevant information about that VBScript keyword and any examples provided by The second action is a pure advertisement for

How to Implement a List

The smart tag list component gets all its information from an XML file, msotl.xml. This file contains the list of terms, the actions you want to define, and some naming information about the smart tag itself. The first thing you need to do is set the name of the smart tag list, in this case "Script Terms," and then a description of what the smart tag list is about. Once you've done this, next set the terms that will be used for the smart tag list. The XML definition provides a termlist element, which you fill with a comma-separated list of terms:

SAMPLE ONE: (below)

In this example, I've only used a few VBScript terms to keep it simple.

Once all the terms have been defined, all that's left to do is to setup the actions that will show up when the user clicks on the smart tag. The List XML definition includes an element that contains all the actions that will show up. Each action has a caption and URL that should be called when the user selects the menu item. In this example, I've added a gethelp action and a gratuitous advert for The gethelp action includes a URL to the getref.asp page that takes the name of the term as an argument. This is simple to achieve, since {TEXT} is substituted with the term that caused the smart tag to be invoked.

XML to define actions:

SAMPLE TWO: (below)

Figure 2. What the smart tag looks like in Word

Once all the information is entered into the msotl.xml file, all that is required is to save the file back to the appropriate location on the machine. If the list is going to be made available to all users, then save it to program files\common files\microsoft shared\smart tags\lists. If it's for a specific user, then save it to drive:\Documents and Settings\username\Application Data\Microsoft\Smart Tag Lists, which will ensure that the list can roam with the user.

Example msotl.xml:


Implementing the Help ASP Page

To keep the example for this article simple, I've implemented a rudimentary help page that just returns the documentation for the particular term that help is being asked for. Ideally this would be stored in a database, and the ASP page would query the database based on the term being queried. I cheated in this example by storing the documentation in files in a subfolder, and by just loading the appropriate file for the term being queried-pretty low tech I know, but it does keep the page simple.

SAMPLE FOUR: (below)

The key to this example is that it's simple to build in links between Office smart tags and scripts running on your server. The example used here, script terms, is probably not the most useful of examples, but it illustrates the point of how you can get your information into Office. I encourage you to try out the XML-based smart tags feature and integrate it with script on the server.

As always, we look forward to hearing your feedback and ideas for making scripting easier. Please feel free to contact us at [email protected] and to use the newsgroups on

Complete Article

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.