How to Execute a SQL Server Stored Procedure from Excel with VBA
Apr 10, 2023
I needed to execute a Stored Procedure (from SQL Server), which would return a query. I then had to display the results in my Excel sheet.
This pairs nicely with a tutorial I wrote on how to import data from Excel into SQL Server
The code is below.
I ran the sub getDataFromRecordset (line 41) which called the function getInfoFromStoredProcedure (line 4).
The results print out in Row 2 of the spreadsheet, so that column headers could be in Row 1. The last few lines format the output to make it easier to read.