Here's one example which returns a SQL Server recordset to Excel.
Sub RecordsetToXL()
Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As ADODB.Recordset
cn.Open "Driver=SQL
Server;Server=<Your_Server>;Database=<Your_Database>"
If cn.State = adStateOpen Then
With cmd
' set the command object properties
.ActiveConnection = cn
.CommandText = "<Your_Stored_Proc_Name>"
.CommandType = adCmdStoredProc
' .Parameters("@OptionalParameterName").Value = "ParamValue"
Set rs = .Execute
' Stick in a sheet
Range("A1").CopyFromRecordset rs
End With
End If
Set cmd = Nothing
If rs.State = adStateOpen Then
rs.Close
End If
If cn.State = adStateOpen Then
cn.Close
End If
Set cn = Nothing
Set rs = Nothing
End Sub
This connection string above uses the "bare minimum" for Windows
authentication.
See
www.connectionstrings.com for many more connection string examples.