1

What is the syntax to call stored procedure in SQL Server from Excel (VBA) using windows authentication?

1 Answer 1

1
'Remember to reference Microsoft ActiveX Data Objects via Tools - References

Dim strConn As String
Dim conn As New Connection
Dim cmd As New ADODB.Command
Dim rs As New Recordset
strConn = "DRIVER=SQL Server;SERVER=ServerName;DATABASE=DBname"

conn.ConnectionString = strConn
conn.Open
cmd.ActiveConnection = conn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "SPName"
cmd.Parameters.Refresh 'requires a trip to server / can add parameters manually using cmd.Parameters.Append
cmd.Parameters("@Param1").Value = ""
Set rs = cmd.Execute
If Not rs.EOF Then
    'your code here
End If
conn.Close
Set rs = Nothing
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.