Partager via


QueryTables.Add Method

Creates a new query table. Returns a QueryTable object that represents the new query table.

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

Syntax

'Declaration
Function Add ( _
    Connection As Object, _
    Destination As Range, _
    Sql As Object _
) As QueryTable
'Usage
Dim instance As QueryTables
Dim Connection As Object
Dim Destination As Range
Dim Sql As Object
Dim returnValue As QueryTable

returnValue = instance.Add(Connection, _
    Destination, Sql)
QueryTable Add(
    Object Connection,
    Range Destination,
    Object Sql
)

Parameters

  • Connection
    Type: System.Object

    Required Object. The data source for the query table. Can be one of the following:

    A string containing an OLE DB or ODBC connection string. The ODBC connection string has the form "ODBC;<connection string>".

    • A QueryTable object from which the query information is initially copied, including the connection string and the SQL text, but not including the Destination range. Specifying a QueryTable object causes the Sql argument to be ignored.

    • An ADO or DAO Recordset object. Data is read from the ADO or DAO recordset. Microsoft Excel retains the recordset until the query table is deleted or the connection is changed. The resulting query table cannot be edited.

    • A Web query. A string in the form "URL;<url>", where "URL;" is required but not localized and the rest of the string is used for the URL of the Web query.

    • Data Finder. A string in the form "FINDER;<data finder file path>" where "FINDER;" is required but not localized. The rest of the string is the path and file name of a Data Finder file (*.dqy or *.iqy). The file is read when the Add method is run; subsequent calls to the Connection property of the query table will return strings beginning with "ODBC;" or "URL;" as appropriate.

    • A text file. A string in the form "TEXT;<text file path and name>", where TEXT is required but not localized.

  • Destination
    Type: Microsoft.Office.Interop.Excel.Range

    Required Range. The cell in the upper-left corner of the query table destination range (the range where the resulting query table will be placed). The destination range must be on the worksheet that contains the QueryTables object.

  • Sql
    Type: System.Object

    Optional Object. The SQL query string to be run on the ODBC data source. This argument is optional when you're using an ODBC data source You cannot use this argument when a QueryTable object, text file, or ADO or DAO Recordset object is specified as the data source.

Return Value

Type: Microsoft.Office.Interop.Excel.QueryTable

Remarks

A query created by this method isn't run until the Refresh method is called.

See Also

Reference

QueryTables Interface

QueryTables Members

Microsoft.Office.Interop.Excel Namespace