Action Class

Represents a Visual Studio Tools for Office smart tag action in a Microsoft Office Excel workbook.

Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in

public class Action : ActionBase

Actions are the choices available on the smart tag shortcut menu when a smart tag of a certain type is recognized. An example of a possible action is "Add name to the Contacts folder" for a string of type Person's Name. For more information about smart tags in Visual Studio Tools for Office, see Smart Tags Architecture.

The following code example creates a SmartTag with an Action that recognizes the term "sale" and the regular expression "[I|i]ssue\s\d{5,6}". The action modifies the menu caption of the action at run time and displays the address of the text that was recognized. To test the example, type the word "sale" in one cell and the string "issue 12345" in another cell, and then try the smart tag action.

#region Smart Tag Example

private Microsoft.Office.Tools.Excel.Action DisplayAddress;

private void AddSmartTag()
    Microsoft.Office.Tools.Excel.SmartTag SmartTagDemo =
        new Microsoft.Office.Tools.Excel.SmartTag(
        "Demonstration Smart Tag");

    // Specify a term and an expression to recognize.
        new System.Text.RegularExpressions.Regex(

    // Create the action.
    DisplayAddress = new Microsoft.Office.Tools.Excel.Action(
        "To be replaced");

    // Add the action to the smart tag.
    SmartTagDemo.Actions = new
        Microsoft.Office.Tools.Excel.Action[] { 
        DisplayAddress };

    // Add the smart tag to the workbook.

    DisplayAddress.BeforeCaptionShow += new 

    DisplayAddress.Click += new 

void DisplayAddress_BeforeCaptionShow(object sender, 
    Microsoft.Office.Tools.Excel.ActionEventArgs e)
    DisplayAddress.Caption = "Display the address of " + 

void DisplayAddress_Click(object sender, 
    Microsoft.Office.Tools.Excel.ActionEventArgs e)
    string smartTagAddress = e.Range.get_Address(missing,
        missing, Excel.XlReferenceStyle.xlA1, missing, missing);
    MessageBox.Show("The recognized text '" + e.Text +
        "' is at range " + smartTagAddress);



Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.