使用多个输出在VBA中执行SQL Server存储过程

我在SQL Server中有一个存储过程,我试图通过一些VBA代码从Excel执行。 但是,存储过程有两个输出(见下文)。

我的logging集只拉第一个表(添加0错误消息…),而我想拉第二个表。

图片在这里: http : //i.stack.imgur.com/LxyLi.png

这里是我的代码,从我在这里find的其他来源编译:

Sub RefreshBarcodes() Dim Database As String Dim con As ADODB.Connection Dim strconn As String Dim SQLServer As String Dim Session As String Dim strSQLCommandOne As String Application.ScreenUpdating = False Worksheets("Master").Activate Database = Worksheets("Master").Cells(5, "H").Value SQLServer = Worksheets("Master").Cells(4, "H").Value Session = Worksheets("Master").Cells(6, "H").Value 'Connect to Database Set con = New ADODB.Connection strconn = "Provider=sqloledb; Data Source=" & SQLServer & ";Initial Catalog = " & _ Database & "; INTEGRATED SECURITY=SSPI; " con.Open strconn 'Set SQL Commands strSQLCommandOne = "set nocount on; exec spGetSessionSourceCounts 'HNW-CLU-001-024_01_0005'" 'Open Recordset Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset 'Execute and copy to Excel rs.Open strSQLCommandOne, strconn rs.MoveFirst Worksheets("Session").Activate Cells(1, 1).Select ActiveCell.CopyFromRecordset rs rs.Close Worksheets("Master").Activate Cells(6, "H").Value = "Session updated" con.Close Application.ScreenUpdating = True End Sub 

Excel输出: http : //i.stack.imgur.com/b7i3B.png

我希望能够拉第一个(错误信息)和第二个结果(会话信息),但主要只需要第二个表。 非常感谢!

要访问第二个logging集,你需要执行这一行: –

 'Activate the next available recordset Set rs = rs.NextRecordset If Not rs Is Nothing Then 'Add code in here End If