How to execute a stored SQL procedure in Microsoft Excel?
This is a job for an ADODB connection in VBA. Here's a link with a sample code for a simple SELECT query, but this will handle stored procedures just as well.
http://www.ozgrid.com/forum/showthread.php?t=83016&page=1
The key items are the need to declare an ADODB.Connection
, ADODB.Recordset
, and a connection string that matches your database. After opening the connection, you execute your SQL statement using syntax like the following (taken from the link):
With cnt
.CursorLocation = adUseClient
.Open stADO // stADO is the connection string.
.CommandTimeout = 0
Set rst = .Execute(stSQL)
End With
Then move the data from your recordset (rst
, above) into a range using Range.CopyFromRecordSet
.