Assembly: Microsoft.Office.Interop.Excel (in microsoft.office.interop.excel.dll)
QueryTable Add( [In] object Connection, [In] Range Destination, [In, Optional] object Sql );
public QueryTable Add( /*in*/System.Object Connection, /*in*/Range Destination, /*in*/System.Object Sql );
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.
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.
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.