View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
K Dales[_2_] K Dales[_2_] is offline
external usenet poster
 
Posts: 1,163
Default Retrieving the SQL query of the external data range

Yes, the QueryTable.CommandText property should contain the SQL query used;
and the other properties like the Connection property might help you find out
what the data source is (should be) and why it isn't connecting - perhaps
either the database was moved, or there is a new ODBC driver.

To get to the Querytable to see these things:
Dim MyQueryTable as QueryTable
Set MyQueryTable = Sheets("SheetName").Querytables("QueryTableName")

To find the querytable's name, right click on the query results range and
look at the properties.

"Pavils Jurjans" wrote:

Hello,

I have this Excel file with a spreadsheet with external data range. It was
given to me to work though the associated SQL query remotely. Unfortunately,
when I click "Edit Query", I get message that ODBC data source could not be
found. Currently I have no copy of the data, but I'd be willing to study
(and perhaps update) the SQL query.

Is there any way to retrieve the SQL query that is saved in my Excel file,
via other means, for example, using VBA?

Thanks,

Pavils