我試圖在vba下運行,但不幸的是,當我添加參數範圍其不工作(沒有任何錯誤沒有做任何事情),但如果我用簡單的選擇代碼它的工作完美..請幫助!運行SQL存儲過程從Excel VBA使用EXcel參數
Dim HRCONN As ADODB.Connection
Dim HRDATA As ADODB.Recordset
Dim HRFIELD As ADODB.FIELD
Set HRCONN = New ADODB.Connection
Set HRDATA = New ADODB.Recordset
HRCONN.connectionstring = CONSTRSQL
HRCONN.Open
On Error GoTo closeconnection
With HRDATA
.ACTIVECONNECTION = HRCONN
.Source = "EXEC DBO.LATENCY_REPORT" & "'" & Range("M12").Value & "'" & "," & "'" & Range("M13").Value & "'" & "," & "'" & Range("B12").Value & "'"""
.locktype = adLockReadOnly
.cursortype = adopenforwardonly
.Open
End With
On Error GoTo closerecordset
Worksheets.Add
For Each HRFIELD In HRDATA.Fields
ActiveCell.Value = HRFIELD.Name
ActiveCell.Offset(0, 1).Select
Next HRFIELD
Range("A1").Select
Range("A2").CopyFromRecordset HRDATA
Range("A1").CurrentRegion.EntireColumn.AutoFit
On Error GoTo 0
closerecordset:
HRDATA.Close
closeconnection:
HRCONN.Close
End Sub
你能告訴我你在代碼中添加參數的位置嗎? –