0 out of 7 rated this helpful - Rate this topic

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)

'Usage
Dim Connection As Object
Dim Destination As Range
Dim Sql As Object
Dim returnValue As QueryTable
Dim queryTables1 As QueryTables
returnValue = queryTables1.Add(Connection, Destination, Sql)
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
);
function Add(
	 Connection : Object, 
	 Destination : Range, 
	 Sql : Object
) : QueryTable;

Parameters

Connection

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

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

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.

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


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Development Platforms

Windows XP Home Edition, Windows XP Professional, Windows Server 2003, and Windows 2000

Target Platforms

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.