#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Data import

I am trying to create a function that extracts data from a
Sql Server into Excel.

My current design which looks something like below, works
O.K using "QueryTables.Add" but problem is that it can
only return to a range on the worksheet, well as i want
result returned to a variable which I can manipulate
further.

Does anyone know of a way of achieving this.

Function xyz

connstring = _
"ODBC;DSN=CSTW2K.SUNDB;UID=sa;PWD="
With ActiveSheet.QueryTables.Add(
Connection:=connstring, _
Destination:=Range("a11"), Sql:=sqlstring)
.RefreshOnFileOpen = False
xlInsertDeleteCells
.Refresh
End With


End Function


N.B I tried using "SQLRequest" which returns an array but
I could not solve problem with "XLOdbc" that it kept
referring to.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Data import

Try using ADO:

http://www.erlandsendata.no/english/vba/adodao/

Examples are to Access, but should be adaptable to SQL Server.

--
Regards,
Tom Ogilvy


"gerald" wrote in message
...
I am trying to create a function that extracts data from a
Sql Server into Excel.

My current design which looks something like below, works
O.K using "QueryTables.Add" but problem is that it can
only return to a range on the worksheet, well as i want
result returned to a variable which I can manipulate
further.

Does anyone know of a way of achieving this.

Function xyz

connstring = _
"ODBC;DSN=CSTW2K.SUNDB;UID=sa;PWD="
With ActiveSheet.QueryTables.Add(
Connection:=connstring, _
Destination:=Range("a11"), Sql:=sqlstring)
.RefreshOnFileOpen = False
xlInsertDeleteCells
.Refresh
End With


End Function


N.B I tried using "SQLRequest" which returns an array but
I could not solve problem with "XLOdbc" that it kept
referring to.




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
import XML data...Is there a size limit on the import? MatthewG Excel Discussion (Misc queries) 0 February 10th 09 05:57 PM
How to Start Excel in Text Import Wizard for data import rlelvis Setting up and Configuration of Excel 0 July 10th 08 08:40 PM
Import external data, data includes Excel function allen davidson Excel Worksheet Functions 0 July 4th 08 12:39 PM
Tool bar: Data/Import external data/New database query Daniel Setting up and Configuration of Excel 3 February 28th 08 08:40 AM
how to Import data in excel office2003 with data more 65000 rows Abhijit Excel Worksheet Functions 1 May 13th 05 05:12 AM


All times are GMT +1. The time now is 03:07 AM.

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

About Us

"It's about Microsoft Excel"