How to create a smart tag for Office 2007, 2003 and 2002
for Microsoft Word, Excel, Outlook and PowerPoint
Add-in Express
for Microsoft .net
Add-in Express Home > Add-in Express.NET > Online Guide > Programming Office smart tags
Creating smart tags
Smart Tags is a technology introduced in Microsoft Office 2002 (XP) that provides Microsoft Office 2007 - 2002 users with more interactivity for the content of their Office documents. A SmartTag is an element of text in an Office document that is recognized as having custom actions associated with it. An example of one of these special elements of text might be an e-mail name that is typed into a Word document or an Excel workbook. If the e-mail name is recognized as a smart tag, the user is presented with one or more actions to perform on the specified text. Possible actions associated with an e-mail name are to look up additional contact information, or send a new e-mail message to that contact.
Add-in Express .NET allows you to create a new smart tag for Microsoft Excel, Word, Outlook (with Word as a default e-mail editor) and PowerPoint in Office 2007, Office 2003 and 2002 (XP). But Add-in Express provides a different way including terminology. A smart tag solution based on Add-in Express implements one smart tag recognizer, but we call this solution a SmartTag library. The point is that Add-in Express architecture allows you to create several smart tags within one solution and one recognizer. That is why we regard smart tag solutions based on Add-in Express as smart tag libraries rather than one smart tag.
Example of a Word smart tag project
The smart tag project below is for Word 2002 (XP), 2003, and Word 2007. The smart tag is written in VB.NET, but you can also build your smart tags in C# and C++. One more sample smart tag for Word 2007 is also available.
Step #1 – Creating a new smart tag library project
Add-in Express .NET provides a SmartTag project template that you find in the New Project dialog: choose "File | New | Project..." and select the "Other Projects | Extensibility Projects" item.

Select the template and click OK. The Add-in Express SmartTag wizard starts and prompts you for the programming language and setup project options.

This VB.NET sample shows an Add-in Express SmartTag project with the Add-in Express Loader as a shim. To understand shims and the Add-in Express Loader, see Deploying Add-in Express projects. The Add-in Express Project Wizard then generates and opens the Smart Tag solution in Visual Studio .NET. The solution includes the SmartTag project and the setup project.
Note! Do not delete the SmartTagImpl.vb file required by the Add-in Express implementation of the Smart Tag technology. Usually, you do not need to modify it.

The Smart Tag project contains the SmartTagModule.vb (or SmartTagModule.cs) file described in the next step.
Step #2 – Add-in Express Smart Tag module
The SmartTagModule.vb (or SmartTagModule.cs) file is a SmartTag module that is the core part of the Smart Tag project: it centralizes the applied code of all smart tags and acts as a container for ADXSmartTag components that are representations of smart tags. The components allow you to specify words or phrases recognizable by smart tags and to add corresponding custom actions. The module contains the SmartTagModule class that implements interfaces required by the Smart Tag technology and allows managing smart tags and their code. To review its source code, in the Solution Explorer window, right-click the SmartTagModule.vb (or SmartTagModule.cs) file and choose the View Code popup menu item.

The smart tag module contains the following code:
Imports System.Runtime.InteropServices
Imports System.ComponentModel
'Add-in Express Smart Tag Module
<GuidAttribute("6FFEFD7D-FD3C-47EE-AE67-A84DE4AD4E7A"),
ProgIdAttribute("MySmartTag1.SmartTagModule")> _
Public Class SmartTagModule
Inherits AddinExpress.SmartTag.ADXSmartTagModule
#Region " Component Designer generated code. "
'Required by designer
Private components As System.ComponentModel.IContainer
'Required by designer - do not modify
'the following method
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
'
'SmartTagModule
'
Me.NamespaceURI = "mysmarttag1/smarttagmodule"
Me.LibraryName = New AddinExpress.SmartTag.ADXLocalizedList
Me.LibraryName.Add(0, "MySmartTag1")
Me.Description = New AddinExpress.SmartTag.ADXLocalizedList
Me.Description.Add(0, "This is a description")
End Sub
#End Region
#Region " Add-in Express automatic code "
'Required by Add-in Express - do not modify
'the methods within this region
Public Overrides Function GetContainer() As
System.ComponentModel.IContainer
If components Is Nothing Then
components = New System.ComponentModel.Container
End If
GetContainer = components
End Function
<ComRegisterFunctionAttribute()> _
Public Shared Sub SmartTagRegister(ByVal t As Type)
AddinExpress.SmartTag.ADXSmartTagModule.ADXSmartTagRegister(t, _
System.Type.GetType("MySmartTag1.SmartTagRecognizerImpl"), _
System.Type.GetType("MySmartTag1.SmartTagActionImpl"))
End Sub
<ComUnregisterFunctionAttribute()> _
Public Shared Sub SmartTagUnregister(ByVal t As Type)
AddinExpress.SmartTag.ADXSmartTagModule.ADXSmartTagUnregister(t, _
System.Type.GetType("MySmartTag1.SmartTagRecognizerImpl"), _
System.Type.GetType("MySmartTag1.SmartTagActionImpl"))
End Sub
#End Region
Public Sub New()
MyBase.New()
'This call is required by the Component Designer
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
End Class
Step #3 – Smart Tag designer
The Add-in Express SmartTag Designer allows setting Smart Tag properties and adding components to the module. In the Solution Explorer window, right-click the SmartTagModule.vb (or SmartTagModule.cs) file and choose the View Designer popup menu item.
|
|
|
In the Properties window, you set properties of your Smart Tag module (see Smart Tag designer).To add an Add-in Express Component to the module, you use an appropriate command in the Properties window, or you can right-click the designer surface and choose the same command in the context menu.

The only command available for the module adds the Smart Tag component to the module.
Step #4 – Adding a new smart tag
To add a new smart tag to your library, open the Smart Tag module in the design view and use the Add Smart Tag command that adds a new ADXSmartTag component to the SmartTag module (see Smart Tags designer). This adds a smart tag component to the module.

Select the newly added ADXSmartTag component and, in the Properties window, specify the caption for the added smart tag using the Caption property. The value of this property will become a caption of the smart tag context menu. Also, specify the phrase(s) recognizable by the smart tag in the RecognizedWords string collection.

In this sample Smart Tag, the words are as follows:

Step #5 – Adding and handling smart tag actions
Now you add smart tag actions and their captions to your smart tag context menu. To add a new smart tag action, add an item to the Actions collection of your smart tag.

The value of the action's Caption property will become the caption of the appropriate item in the smart tag context menu. To handle the Click event of the action, close the Actions collection editor, and, in the Properties window, select the added action. Then add the Click event handler and write your code to handle the event:
Private Sub AdxSmartTagAction1_Click(ByVal sender As System.Object, _
ByVal e As AddinExpress.SmartTag.ADXSmartTagActionEventArgs) _
Handles AdxSmartTagAction1.Click
MsgBox("Recognized text is '" + e.Text + "'!")
End Sub
Step #6 - Running your smart tag
Choose the Register Add-in Express Project item in the Build menu. Restart Word, put the words recognizable by your smart tag into a document, and see if the smart tag works.

In Office 2003 - 2003, choose the Tools | AutoCorrect menu item and find your smart tag on the Smart Tags tab. In Office 2007, the path to this dialog is as follows: Office button | Word Options | Add-ins | Mange | Manage Smart Tags | Go.

Step #7 – Debugging the smart tag
To debug your smart tag, just specify the add-in host application as the Start Program in the Project Options window.

When debugging an add-in or a smart tag on Visual Studio 2003 and Office 2002 (XP) you cannot see your add-in or smart tag on the COM add-ins or AutoCorrect dialog box. This is a “feature” of Office XP "added" by Microsoft.
Step #8 – Deploying the smart tag
Just built the setup project, copy all setup files to the target PC and run the setup.exe file to install the smart tag. See also Deploying Add-in Express projects and Deploying Office add-ins tips.
Back to Add-in Express.NET homepage



