Syntax

expression.Connection

expression An expression that returns a QueryTable object.

Remarks

Setting the Connection property doesn't immediately initiate the connection to the data source. You must use the method to make the connection and retrieve the data.

For more information about the connection string syntax, see the method of the QueryTables collection.

Alternatively, you may choose to access a data source directly by using the Microsoft ActiveX Data Objects (ADO) library instead.

Example

This example supplies new ODBC connection information for the first query table on the first worksheet.

Visual Basic for Applications
Worksheets(1).QueryTables(1) _ .Connection:="ODBC;DSN=96SalesData;UID=Rep21;PWD=NUyHwYQI;"

This example specifies a text file.

Visual Basic for Applications
Worksheets(1).QueryTables(1) _ Connection := "TEXT;C:\My Documents\19980331.txt"

See also: