SmartTagCollection Interface

Represents a collection of smart tags in a Word or Excel solution created by using the Office development tools in Visual Studio.

Namespace:  Microsoft.Office.Tools
Assembly:  Microsoft.Office.Tools.Common (in Microsoft.Office.Tools.Common.dll)

Syntax

'Declaration
<GuidAttribute("30a90086-8c89-4e19-8299-47765d808408")> _
Public Interface SmartTagCollection _
    Inherits IEnumerable, IDisposable
[GuidAttribute("30a90086-8c89-4e19-8299-47765d808408")]
public interface SmartTagCollection : IEnumerable, 
    IDisposable

The SmartTagCollection type exposes the following members.

Properties

  Name Description
Public property Item Gets the smart tag at the specified index.

Top

Methods

  Name Description
Public method Add Adds a smart tag to the end of the SmartTagCollection.
Public method AddRange Adds an array of smart tags to the end of the SmartTagCollection.
Public method BeginInit Infrastructure.
Public method Contains Determines whether the SmartTagCollection contains a specific smart tag.
Public method CopyTo Copies the smart tags in the SmartTagCollection to a one-dimensional array of smart tags, starting at a specified index.
Public method Dispose Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.)
Public method EndInit Infrastructure.
Public method GetEnumerator Returns an enumerator that iterates through a collection. (Inherited from IEnumerable.)
Public method IndexOf Determines the index of a specified smart tag in the SmartTagCollection.
Public method Insert Inserts a smart tag into the SmartTagCollection at the specified index.
Public method Remove Removes a smart tag from the SmartTagCollection.

Top

Remarks

When you create a smart tag, you add a SmartTagBase object to the Workbook.VstoSmartTags or Document.VstoSmartTags properties. These properties have the type SmartTagCollection.

For more information about smart tags in Office solutions, see Smart Tags Overview.

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 and Word 2007. Smart tags are deprecated in Excel 2010 and Word 2010. For more information, see Smart Tags Overview.

This documentation describes the version of this type that is used in Office projects that target the .NET Framework 4. 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: https://go.microsoft.com/fwlink/?LinkId=160658.

Examples

The following code uses the Add method to add a Microsoft.Office.Tools.Excel.SmartTag to the collection of smart tags exposed by the Workbook.VstoSmartTags property. This code example is part of a larger example provided for Microsoft.Office.Tools.Excel.Action.

This example is for a document-level customization.

WithEvents displayAddress As Microsoft.Office.Tools.Excel.Action

Private Sub AddSmartTag()

    ' Create the smart tag for .NET Framework 4 projects.
    Dim smartTagDemo As Microsoft.Office.Tools.Excel.SmartTag = _
        Globals.Factory.CreateSmartTag(
        "www.microsoft.com/Demo#DemoSmartTag",
        "Demonstration Smart Tag")

    ' For .NET Framework 3.5 projects, use the following code to create the smart tag.
    ' Dim smartTagDemo As New  _
    '    Microsoft.Office.Tools.Excel.SmartTag( _
    '    "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}"))

    ' Create the action for .NET Framework 4 projects.
    displayAddress = Globals.Factory.CreateAction("To be replaced")

    ' For .NET Framework 3.5 projects, use the following code to 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.
    Me.VstoSmartTags.Add(smartTagDemo)
End Sub
private Microsoft.Office.Tools.Excel.Action displayAddress;

private void AddSmartTag()
{
    // Create the smart tag for .NET Framework 4 projects.
    Microsoft.Office.Tools.Excel.SmartTag smartTagDemo =
        Globals.Factory.CreateSmartTag(
            "www.microsoft.com/Demo#DemoSmartTag",
            "Demonstration Smart Tag");

    // For .NET Framework 3.5 projects, use the following code to create the smart tag.
    // Microsoft.Office.Tools.Excel.SmartTag smartTagDemo =
        // new Microsoft.Office.Tools.Excel.SmartTag(
        //     "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}"));

    // Create the action for .NET Framework 4 projects.
    displayAddress = Globals.Factory.CreateAction("To be replaced");

    // For .NET Framework 3.5 projects, use the following code to 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.
    this.VstoSmartTags.Add(smartTagDemo);

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

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

See Also

Reference

Microsoft.Office.Tools Namespace

Other Resources

Smart Tags Overview