Creating your own smart tags in Excel

Microsoft Excel provides two smart tag recognizers that allow users a convenient interface for accomplishing tasks or linking to the Web from the worksheet, but it is also possible for organizations to develop smart tags specific to their business or organizational needs.

What are smart tags?

A smart tag is a button in the user interface in Excel or Microsoft Word 2002 that allows users to accomplish simple tasks or connect to the Web from within an application. In Excel, a user can provide a financial symbol or a recently used e-mail name and choose from actions associated with the symbol or name. For example, if you enable MSN MoneyCentral Financial Symbols smart tags and type MSFT into a spreadsheet cell, a smart tag actions list gives you options for inserting a refreshable stock price in your worksheet, finding out more about the company by linking to an information web, linking to recent news about the company on MoneyCentral, and more.

Play Demo

In addition, Office XP supports exposing smart tag actions within Microsoft Internet Explorer so that documents created with Word or Excel will retain smart tags when viewed as a web page.

What smart tags can do for you

Smart tag development scenarios are limited only by imagination, but their applications in a business environment are particularly compelling.

Business scenario

Louise runs the IT department for a Fortune 500 company. One of her company's goals is to make it easy for knowledge workers to connect to information associated with the contents of a document. For example, when a customer makes an e-mail inquiry, sales personnel often look up current pricing information or quantity of inventory on hand before sending out a quote to the customer. Typically, this sales task required several steps: copying the name of the product from the mail, opening the inventory or price database, pasting in the product name, running a query, and then copying the information from the database. But now, Louise has written a database lookup smart tag recognizer and an action to look up the price and quantity on hand in the appropriate database, and the information is available to the sales person who can click an action from a list in the user interface and choose either the Current price or Quantity check actions.

Developing Smart Tags

If you are familiar with Component Object Model (COM) interfaces or developing COM add-ins, writing great smart tag add-ins is a snap. Two interfaces are required to write smart tag add-ins: ISmartTagRecognizer (ISTR) and ISmartTagAction (ISTA). ISTA and ISTR are callback-style interfaces. The add-ins register themselves by way of the Microsoft Windows registry; applications call into the DLLs to find out more about the kind of types and actions or recognition that the DLL supports. ISTRs are add-ins that run in the background and annotate text passed to them from hosts. ISTAs implement the actions that perform user tasks.

A smart tag DLL can be designed to recognize text in a document (or email). If text is recognized, the DLL marks up the text as recognized with an XML local part. For example, <st1:number>P123</st1:number>. The local part corresponds to a namespace you can choose yourself. You might pick urn:schemas-item-com as the namespace Excel or Word will store in the html file and refer to with the shorthand st1.

A smart tag DLL contains code that implements "actions" based on recognized text. So if the text is a product number, the smart tag can support any number of associated actions for that product (for example, look up the product on an intranet or in a database). For actions to be recognized, however, the user must choose the smart tag action command.

Smart tag types are the unifying elements of smart tag actions and recognizers. ISTRs attach smart tag types to data; ISTAs register verbs that work in conjunction with smart tag types. A smart tag type has the form NamespaceURI#TagName. For example, the 'person' type recognized by Office is represented as:

urn:schemas-microsoft-com:office:smarttags#PersonName

The namespace is designed to resolve conflicts against differing notions of how to represent the same type of data. The tag name is an identifier for the type of data being recognized.

Security

Because smart tags are COM DLLs and not script, a user must download the action smart DLL and install it on the client computer for smart tags to be implemented. Smart tag DLLs, like custom templates, add-ins, and COM add-in DLLs, recognize Microsoft Office security settings.

For more information about developing smart tags, install the Smart Tag SDK, which contains code samples and tutorials, and documents all facets of smart tag add-in development. You can find this on the MSDN Web site.

 
 
Applies to:
Excel 2002