S sal21 Jun 14, 2006 #1 ....need example to import and export from SQL SERVER to Excel via VBA for Excel. Tks for help.
G Guest Jun 14, 2006 #2 sal21 said: ...need example to import and export from SQL SERVER to Excel via VBA for Excel. Click to expand... 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
sal21 said: ...need example to import and export from SQL SERVER to Excel via VBA for Excel. Click to expand... 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