Skip to content

Instantly share code, notes, and snippets.

@stevesohcot
Created August 7, 2023 14:26
Show Gist options
  • Save stevesohcot/4937c90667c0db9e5741725a6bbfdd50 to your computer and use it in GitHub Desktop.
Save stevesohcot/4937c90667c0db9e5741725a6bbfdd50 to your computer and use it in GitHub Desktop.
Excel VBA call function for Stored Procedure
Public Sub getDataFromRecordset()
Dim sheet As String
sheet = "Data"
Worksheets(sheet).Select
Range("A1").Select
Set rPrint = Worksheets(sheet).Range("A2")
Dim rst As New ADODB.Recordset
Set rst = getInfoFromStoredProcedure()
If Not rst.EOF Then
rPrint.CopyFromRecordset rst
End If
rst.Close
' Cells.Select
' Selection.ColumnWidth = 50.86
' Cells.EntireColumn.AutoFit
' Cells.EntireRow.AutoFit
Range("A1").Select
MsgBox " Report downloaded"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment