Share via


ApplicationFactory.HasVstoObject Method (ListObject)

Returns a value that indicates whether a Microsoft.Office.Tools.Excel.ListObject exists for the specified native list object.

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

Syntax

'Declaration
Function HasVstoObject ( _
    listObject As ListObject _
) As Boolean
bool HasVstoObject(
    ListObject listObject
)

Parameters

Return Value

Type: System.Boolean
true if a Microsoft.Office.Tools.Excel.ListObject exists for the specified Microsoft.Office.Interop.Excel.ListObject object; otherwise, false.

Examples

The following code example checks each native list object in a worksheet to determine if the list object has an associated host item. To use this code, run it from the ThisAddIn class in an Excel add-in project that targets the .NET Framework 4.

Dim mySheet As Excel.Worksheet = Me.Application.ActiveSheet
If mySheet.ListObjects.Count > 0 Then
    For Each list As Excel.ListObject In mySheet.ListObjects
        If Globals.Factory.HasVstoObject(list) = True Then
            System.Windows.Forms.MessageBox.Show( _
                "The VSTO properties of list objects are not " _
                + "persisted when you save and close this workbook.", _
                "VSTO ListObject", _
                System.Windows.Forms.MessageBoxButtons.OK, _
                System.Windows.Forms.MessageBoxIcon.Warning)
            Exit For
        End If
    Next
End If
Excel.Worksheet mySheet = (Excel.Worksheet)
    this.Application.Worksheets["Sheet1"];
if (mySheet.ListObjects.Count > 0)
{
    foreach (Excel.ListObject list in mySheet.ListObjects)
    {
        if (Globals.Factory.HasVstoObject(list) == true)
        {
            System.Windows.Forms.MessageBox.Show(
                "The VSTO properties of list objects are not "
                + "persisted when you save and close this workbook.",
                "VSTO ListObject",
                System.Windows.Forms.MessageBoxButtons.OK,
                System.Windows.Forms.MessageBoxIcon.Warning);
            break;
        }
    }
}

.NET Framework Security

See Also

Reference

ApplicationFactory Interface

HasVstoObject Overload

Microsoft.Office.Tools.Excel Namespace