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,
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
PLS DO NOT PM; OPEN A THREAD INSTEAD!!!
1) Posting Code
[CODE]PasteYourCodeHere[/CODE]
(or paste your code, select it, click # button)
2) Uploading File(s)
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.
3) Testing the Codes
always back up your files before testing the codes.
4) Marking the Thread as Solved
from Thread Tools (on the top right corner, above the first message)
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]
Last edited by Aussiebear; 08-24-2011 at 03:53 PM. Reason: Changed to correct tags