Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default how do I use SQL within vba for excel?

I just want to be able to include SQL statements into a vba environment.
I'm using Office 2003.
Thanks everybody!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default how do I use SQL within vba for excel?

Here's a simple sample sub:

Sub xx()
Cnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\MyExcel.xls;Extended Properties=Excel 8.0;"
Sql = "SELECT * FROM [Sheet1$]"
Set ADORS = CreateObject("ADODB.Recordset")
ADORS.Open Sql, Cnn
End Sub

Create & save a workbook as c:\myexcel.xls (you should populate some columns
in Sheet1) and then run the above sub.

Some hints:

1. You need to know the options for what follows the FROM clause in the
SELECT statement: refer to Excel 2000 VBA (WROX).
2. For information on ADO, download the Microsoft Data Access SDK.
3. Lookup the 'CopyFromRecordset' topic in the Excel help files.
4. You need to learn SQL - there are a lot of materal on the Internet: use
Google to find them.


"macro media" wrote:

I just want to be able to include SQL statements into a vba environment.
I'm using Office 2003.
Thanks everybody!

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



All times are GMT +1. The time now is 09:02 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"