import and export from SQL SERVER to Excel

S

sal21

....need example to import and export from SQL SERVER to Excel via VBA
for Excel. Tks for help.
 
G

Guest

sal21 said:
...need example to import and export from SQL SERVER to Excel via VBA for Excel.

You need an ADO recordset object:

Set RS = CreateObject("ADODB.Recordset")

You need a connection string:

Cn = "DSN=??;uid=??;pwd=??;"

{substitute as necessary, or use other means to connect}

Next open the recordset object:

RS.Open "Your SQL statement", Cn

Now look up CopyFromRecordset in the Excel help files

Close the recordset object.
RS.Close
Set RS = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top