Share via


WorksheetBase.QueryTables Property

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

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

Syntax

'Declaration
Public ReadOnly Property QueryTables As QueryTables
public QueryTables QueryTables { get; }

Property Value

Type: QueryTables
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 QueryTable on the current worksheet.

This example is for a document-level customization.

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
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.");
    }
}

.NET Framework Security

See Also

Reference

WorksheetBase Class

Microsoft.Office.Tools.Excel Namespace