Smart TagRecognizer Object

When you type certain data in Microsoft Excel, data that is recognized by the installed recognition engine is tagged. Use the SmartTagRecognizer object to determine if tag recognizers are enabled for the entire application. The SmartTagRecognizer is a member of the SmartTagRecognizers collection. You can return a single SmartTagRecognizer via the Item property of the SmartTagRecognizers collection.

Now let's spend a few minutes working with the above-mentioned objects.

1. Enter MSFT in cell B5 in any worksheet.

2. Switch to a Visual Basic Editor window.

3. Press Ctrl+G to activate the Immediate window.

4. In the Immediate window, enter the following statements and review the results:

?Range("B5").SrrartTags(1).Name urn:schemas-microsoft-com:office:smarttags#stockticker

?Range("B5").SmartTags(1).SmartTagActions(1).Name Insert refreshable stock price...

Figure C-7:

Properties and methods of the SmartTagAction object

?Range("B5").SmartTags(1).SmartTagActions(2).Name LatestQuoteData

?Range("B5").SmartTags(1).SmartTagActions(2).Parent urn:schemas-microsoft-com:office:smarttags#stockticker

Range("B5").SmartTags(1).SmartTagActions(2).Execute

?Range("B5").SmartTags(1).XML

<xml xmlns:fa1="urn:schemas-rrncrosoft-com:office:smarttags"> _ <fa1:stockticker>MSFT</fa1:stockticker></xml>

The following example procedure relates to the Customer Information smart tag that was created in an earlier section. The procedure illustrates how, by using VBA, you can recognize a customer ID typed into a worksheet cell, even though that particular ID is not stored in the smart tag list description file that was created using the Extensible Markup Language (XML). Recall that the Customer.xml file contains just a few customer IDs. This procedure prompts you for a customer ID and then executes the first smart action, which returns the customer's full name.

Sub AddNExecute_SmartTag() Dim strValue Dim strLink strLink = "urn:schemas-internal-office:northwind#Customers"

' get Customer Id from the user strValue = InputBox("Enter an ID of a Northwind customer " _ & "that is not in the Customer.xml " _ & "Smart Tag list description file:", "Enter: Customer Id")

' exit if user clicked Cancel If strValue = "" Then Exit Sub

' set Smart Tag options to embed and recognize smart tags ActiveWorkbook.SmartTagOptions.EmbedSmartTags = True Application.SmartTagRecognizers.Recognize = True

With Range("B5")

.Formula = strValue

.SmartTags.Add(strLink).SmartTagActions(1).Execute End With End Sub

0 0

Post a comment