次の方法で共有


Action Interface

Definition

Represents a smart tag action in an Excel workbook that is customized by using the Office development tools in Visual Studio.

public interface class Action : Microsoft::Office::Tools::ActionBase
[System.Runtime.InteropServices.Guid("37e25b46-6941-4833-9b08-e692cf461982")]
public interface Action : Microsoft.Office.Tools.ActionBase
[<System.Runtime.InteropServices.Guid("37e25b46-6941-4833-9b08-e692cf461982")>]
type Action = interface
    interface ActionBase
Public Interface Action
Implements ActionBase
Attributes
Implements

Examples

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.

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

    private void AddSmartTag()
    {
        Microsoft.Office.Tools.Excel.SmartTag smartTagDemo =
            Globals.Factory.CreateSmartTag(
                "www.microsoft.com/Demo#DemoSmartTag",
                "Demonstration Smart Tag");

        // Specify a term and an expression to recognize.
        smartTagDemo.Terms.Add("sale");
        smartTagDemo.Expressions.Add(
            new System.Text.RegularExpressions.Regex(
            @"[I|i]ssue\s\d{5,6}"));

        displayAddress = Globals.Factory.CreateAction("To be replaced");


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

        // Add the smart tag.
        this.VstoSmartTags.Add(smartTagDemo);

        displayAddress.BeforeCaptionShow += new 
            Microsoft.Office.Tools.Excel.BeforeCaptionShowEventHandler(
            DisplayAddress_BeforeCaptionShow);

        displayAddress.Click += new 
            Microsoft.Office.Tools.Excel.ActionClickEventHandler(
            DisplayAddress_Click);
    }

    void DisplayAddress_BeforeCaptionShow(object sender, 
        Microsoft.Office.Tools.Excel.ActionEventArgs e)
    {
        Microsoft.Office.Tools.Excel.Action clickedAction =
            sender as Microsoft.Office.Tools.Excel.Action;

        if (clickedAction != null)
        {
            clickedAction.Caption = "Display the address of " +
                e.Text;
        }
    }

    void DisplayAddress_Click(object sender, 
        Microsoft.Office.Tools.Excel.ActionEventArgs e)
    {
        string smartTagAddress = e.Range.get_Address(Excel.XlReferenceStyle.xlA1);
        System.Windows.Forms.MessageBox.Show("The recognized text '" + e.Text +
            "' is at range " + smartTagAddress);
    }
WithEvents displayAddress As Microsoft.Office.Tools.Excel.Action

Private Sub AddSmartTag()

    Dim smartTagDemo As Microsoft.Office.Tools.Excel.SmartTag = _
        Globals.Factory.CreateSmartTag(
        "www.microsoft.com/Demo#DemoSmartTag",
        "Demonstration Smart Tag")

    ' Specify a term and an expression to recognize.
    smartTagDemo.Terms.Add("sale")
    smartTagDemo.Expressions.Add( _
        New System.Text.RegularExpressions.Regex( _
        "[I|i]ssue\s\d{5,6}"))

    displayAddress = Globals.Factory.CreateAction("To be replaced")

    ' Add the action to the smart tag.
    smartTagDemo.Actions = New Microsoft.Office.Tools.Excel.Action() { _
            displayAddress}

    ' Add the smart tag.
    Me.VstoSmartTags.Add(smartTagDemo)
End Sub

Private Sub DisplayAddress_BeforeCaptionShow(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Excel.ActionEventArgs) _
    Handles DisplayAddress.BeforeCaptionShow

    Dim clickedAction As Microsoft.Office.Tools.Excel.Action = _
        TryCast(sender, Microsoft.Office.Tools.Excel.Action)

    If clickedAction IsNot Nothing Then
        clickedAction.Caption = "Display the address of " & e.Text
    End If
End Sub

Private Sub DisplayAddress_Click(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Excel.ActionEventArgs) _
    Handles DisplayAddress.Click

    Dim smartTagAddress As String = e.Range.Address( _
        ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
    MsgBox("The recognized text '" & e.Text & _
            "' is at range " & smartTagAddress)
End Sub

Remarks

Actions are the choices available on the smart tag shortcut menu when a smart tag of a certain type is recognized. To create an action, use the Globals.Factory.CreateAction method to create an Action object..

Note

This interface is implemented by the Visual Studio Tools for Office runtime. It is not intended to be implemented in your code. For more information, see Visual Studio Tools for Office Runtime Overview.

Usage

This type is intended to be used only in projects for Excel 2007. Smart tags are deprecated in Excel 2010..

This documentation describes the version of this type that is used in Office projects that target the .NET Framework 4 or later. In projects that target the .NET Framework 3.5, this type might have different members and the code examples provided for this type might not work. For documentation about this type in projects that target the .NET Framework 3.5, see the following reference section in the Visual Studio 2008 documentation: http://go.microsoft.com/fwlink/?LinkId=160658.

Properties

Caption

Gets or sets the name of the action, as displayed in the smart tag menu. This type or member is intended to be used only in projects for the 2007 Microsoft Office system. Smart tags are deprecated in Office 2010..

(Inherited from ActionBase)

Events

BeforeCaptionShow

Occurs after the user clicks the smart tags icon, and before the smart tag menu is displayed. This type or member is intended to be used only in projects for the 2007 Microsoft Office system. Smart tags are deprecated in Office 2010..

Click

Occurs when the action in the smart tag menu is clicked. This type or member is intended to be used only in projects for the 2007 Microsoft Office system. Smart tags are deprecated in Office 2010..

Applies to