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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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