WorksheetBase.QueryTables Property

Definition

Gets the QueryTables collection that represents all the query tables on the worksheet.

public:
 property Microsoft::Office::Interop::Excel::QueryTables ^ QueryTables { Microsoft::Office::Interop::Excel::QueryTables ^ get(); };
public Microsoft.Office.Interop.Excel.QueryTables QueryTables { get; }
member this.QueryTables : Microsoft.Office.Interop.Excel.QueryTables
Public ReadOnly Property QueryTables As QueryTables

Property Value

The QueryTables collection that represents all the query tables on the worksheet.

Examples

The following code example uses the QueryTables property to refresh the data in every Microsoft.Office.Interop.Excel.QueryTable on the current worksheet.

This example is for a document-level customization.

private void RefreshQueryTables()
{
    if (this.QueryTables.Count > 0)
    {
        for (int i = 1; i <= this.QueryTables.Count; i++)
        {
            if (!this.QueryTables[i].Refresh())
            {
                MessageBox.Show("Refresh of query table " +
                    this.QueryTables[i].Name + " failed.");
            }
        }
    }
    else
    {
        MessageBox.Show("This worksheet contains no query tables.");
    }
}
Private Sub RefreshQueryTables()
    If Me.QueryTables.Count > 0 Then
        Dim i As Integer
        For i = 1 To Me.QueryTables.Count
            If Not Me.QueryTables(i).Refresh() Then
                MsgBox("Refresh of query table " & Me.QueryTables(i).Name & _
                    " failed.")
            End If
        Next i
    Else
        MsgBox("This worksheet contains no query tables.")
    End If
End Sub

Applies to