Connections to multiple Databases with excel vba

phenix4o

New Member
Joined
Jul 13, 2018
Messages
1
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:

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.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,214,968
Messages
6,122,506
Members
449,089
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top