VBAlogging集/ Oracle和Excel Connect

我已经在我的vba语句中安装了试图logging集。 不幸的是,他只访问我的数据库中的第一行。 谁能帮我? 我不擅长VBA这是我的第一个项目。 我希望有人可以帮我用我的代码。 谢谢

Sub Testbox() Dim conn, Rs Dim strSQL As String Dim auswahl As Integer auswahl = MsgBox("Die Daten werden geladen", vbOKCancel, "Bitte auswählen") If auswahl = 1 Then connstring = "UID=user;PWD=passwort;DRIVER={Microsoft ODBC For Oracle};SERVER=server.WORLD;" Set conn = New ADODB.Connection With conn .ConnectionString = connstring .CursorLocation = adUseClient .Mode = adModeRead .Open End With Set Rs = CreateObject("ADODB.Recordset") strSQL = "select * from table where logdatum =1507" Rs.Open strSQL, conn, 3, 3 Range("A2:A5000") = Rs("scanclient") Range("B2:B500") = Rs("Sum") Range("C2:C500") = Rs("batchclass") Rs.Close Set Rs = Nothing conn.Close Set conn = Nothing Else Exit Sub End If End Sub 

不幸的是,不可能像Recordset一样将数据打印到工作表中:

 Range("A2:A5000") = Rs("scanclient") Range("B2:B500") = Rs("Sum") Range("C2:C500") = Rs("batchclass") 

您需要用下面的代码replace这个代码:

 Dim i As Long: i = 1 Do Until Rs.EOF i = i + 1 Cells(i, 1) = Rs("scanclient") Cells(i, 2) = Rs("Sum") Cells(i, 3) = Rs("batchclass") Call Rs.MoveNext Loop