Hi,
I need to get data from MS SQL Server to Excel and vice versa.
Could you please send me the code for that.
Thanks for your help.
Printable View
Hi,
I need to get data from MS SQL Server to Excel and vice versa.
Could you please send me the code for that.
Thanks for your help.
hi.
google search:
xl -> sql
http://support.microsoft.com/kb/321686
sql -> xl
http://msdn.microsoft.com/en-us/libr...=sql.100).aspx
Try this (Using ADO reference)
refer this website more connection strings http://www.connectionstrings.com
[vba]
Dim db_sl As New ADODB.Connection
Dim rs_sl As New ADODB.Recordset
Dim con_str As String, qry_sl As String
con_str = "Provider=SQLNCLI;Server=YourServerAddress;Database=YourDataBase;Uid=YourUs ername;Pwd=YourPassword;"
rs_sl = "SELECT * FROM tablename" 'Your Query
db_sl.Open con_str
rs_sl.Open qry_sl, db_sl, adOpenStatic, adLockReadOnly
Range("a1").CopyFromRecordset rs_sl 'Get data into Excel
rs_sl.Close
Set rs_sl = Nothing
db_sl.Close
Set db_sl = Nothing
[/vba]