QueryTable.Connection Property (Excel)
Returns or sets a string that contains one of the following: OLE DB settings that enable Microsoft Excel to connect to an OLE DB data source; ODBC settings that enable Microsoft Excel to connect to an ODBC data source; a URL that enables Microsoft Excel to connect to a Web data source; the path to and file name of a text file, or the path to and file name of a file that specifies a database or Web query. Read/write Variant.
Setting the Connection property doesn’t immediately initiate the connection to the data source. You must use the Refresh method to make the connection and retrieve the data.
For more information about the connection string syntax, see the Add 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.
If you import data using the object model, data from a Web query or a text query must be imported as a QueryTable, while all other external data can be imported as either a ListObject or a QueryTable.
You can use the QueryTable property of the ListObject to access the Connection property.
This example supplies new ODBC connection information for the first query table on the first worksheet.
This example specifies a text file.