Hello,
I should make excel vba that queries 80 databases and writes the info in excel.
Is this possible and how to connect to 80 databases? Here is example with the connction to one database:
Please advice how should I make this I am in panic. The databases starts from ds001so to ds010so, then they start from ds0201ts, ds0301ts,ds0401ts and so on.
I should make excel vba that queries 80 databases and writes the info in excel.
Is this possible and how to connect to 80 databases? Here is example with the connction to one database:
Code:
Sub ConnectTOOracle()
Dim cn As New ADODB.Connection
Dim RS As New ADODB.Recordset
Dim Cmd As New ADODB.Command
Dim mtxData As Variant
Dim USR, PWD As String
Dim Server As String
Worksheets("DataSetSheet").Activate
ActiveSheet.ListObjects("TDataSet").DataBodyRange.Value = ""
ActiveSheet.ListObjects("TDataSet").DataBodyRange.Offset(1, 0).Resize(ActiveSheet.ListObjects("TDataSet").DataBodyRange.Rows.Count - 1, _
ActiveSheet.ListObjects("TDataSet").DataBodyRange.Columns.Count).Rows.Delete
PWD = "adm"
USR = "HQ_USER"
Server = "ds001so"
cn.Open "Provider=MSDAORA.Oracle;DATA SOURCE=" & Server & ";" & "USER ID=" & PWD & ";PASSWORD=" & USR
Cmd.ActiveConnection = cn
Cmd.CommandType = adCmdText
Dim sb As String
sb = "select employee_ID, salary, insurance_nr from employee inner join salary on employee.employee_ID= salary.ID"
Cmd.CommandText = sb
Set RS = Cmd.Execute
Range("A6").CopyFromRecordset RS
Cmd.CommandText = sb
Debug.Print (ActiveSheet.ListObjects("TDataSet").DataBodyRange.Rows.Count)
End Sub
Please advice how should I make this I am in panic. The databases starts from ds001so to ds010so, then they start from ds0201ts, ds0301ts,ds0401ts and so on.