Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Retrieving the SQL query of the external data range

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Retrieving the SQL query of the external data range

Give this a shot to get the information you want. Not Tried...

'/=================================================/
Sub Query_Info()
Dim iRow As Long
Dim qryTable As QueryTable
Dim wks As Worksheet

On Error Resume Next

Worksheets.Add.Move _
After:=Worksheets(Worksheets.Count)
Range("A1").Select

ActiveWorkbook.ActiveSheet.Name = "Query Info"

ActiveWorkbook.ActiveSheet.Range("A1").Value = _
"Query Name"
ActiveWorkbook.ActiveSheet.Range("B1").Value = _
"Connection"
ActiveWorkbook.ActiveSheet.Range("C1").Value = _
"SQL"

For Each wks In Worksheets
For Each qryTable In wks.QueryTables
iRow = iRow + 1
ActiveCell.Offset(iRow, 0).Value = _
qryTable.Name
ActiveCell.Offset(iRow, 1).Value = _
qryTable.Connection
ActiveCell.Offset(iRow, 2).Value = _
qryTable.Sql
Next qryTable
Next wks


End Sub
'/=================================================/

HTH,
Gary Brown


"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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify the web link for retrieving data from external sourc Eric Excel Discussion (Misc queries) 16 February 12th 09 01:25 PM
How to modify the web link for retrieving data from external sourc Eric Excel Worksheet Functions 1 January 3rd 07 05:07 AM
Retrieving External Data from Access into Excel Vicki Excel Programming 1 May 26th 04 09:20 AM
Retrieving External Data from Access Vicki Excel Programming 0 May 26th 04 01:16 AM
Retrieving external data Ryan Excel Programming 0 February 20th 04 07:24 PM


All times are GMT +1. The time now is 12:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"