以下是从 oracle 数据库中获取数据到 excel 的 VBA 代码。我希望将与 collabname 301_CBCompanySync_SAP_to_HHT 相关的数据放入名为 301_CBCompanySync_SAP_to_HHT 的表中,而不是将数据放入某个随机表中
与 collabname 302_CBCustomer_SAP_to_HHT 相关的数据将进入名为“302_CBCustomer_SAP_to_HHT”的工作表中......等等
我该如何修改下面的代码
Sub Load_data()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim col As Integer
Dim row As Integer
Dim Query As String
Dim mtxData As Variant
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open ( _
"User ID=xxxx" & _
";Password=xxxxx" & _
";Data Source=xx.xx.xx.xxx:xxxx/xxxxxx" & _
";Provider=OraOLEDB.Oracle")
Dim arrayCollabName As Variant
Dim idx As Integer
idx = 0
arrayCollabName = Array("301_CBCompanySync_SAP_to_HHT", "302_CBCustomer_SAP_to_HHT", "303_CustomerExclusionList_SAP_to_HHT")
For idx = 0 To 2
Sheets("Sheet1").Select
Sheets.Add
rs.Open "select COLLABNAME,DATETIME,TOTALFLOWS,SUCCFLOWS,FAILEDFLOWS from EWS_COLLAB WHERE COLLABNAME like '" & arrayCollabName(idx) & "'", cn
col = 0
Do While col < rs.Fields.Count
.Cells(1, col + 1) = rs.Fields(col).Name
col = col + 1
Loop
mtxData = Application.Transpose(rs.GetRows)
.Range("A2").Resize(UBound(mtxData, 1) - LBound(mtxData, 1) + 1, UBound(mtxData, 2) - LBound(mtxData, 2) + 1) = mtxData
End With
rs.Close
Next
cn.Close
End Sub