Insert Excel data table into Oracle table using ADO - keeps crashing Excel

becci.gott

Board Regular
Joined
Oct 2, 2012
Messages
79
I am trying to upload a data table (approx 20 columns and 3k rows) directly into an Oracle database using the code below (username & password removed for security), but each time I try to run it, Excel is crashing out when it gets to the .Execute (ssql) line.
Public Sub TransfertoOracle()

Dim cn As New ADODB.Connection
Dim tblr as string
Dim tblwb As Workbook
Dim tblws As Worksheet
Set tblwb = ThisWorkbook
Set tblws = tblwb.Sheets("Upload")

tblr = "[" & tblws.Name & "$" & Range("DataTable").Address(False, False) & "]"

With cn
.Open "POLCOMM", "USERID", "PASSWORD"

ssql = "INSERT INTO polreps.temp_sbs_targets "
ssql = ssql & "SELECT * FROM [Excel 8.0;HDR=YES;DATABASE=" & tblwb.FullName & "]." & tblr

.Execute ssql
.Close
End With

Set cn = Nothing

MsgBox "Upload complete"
End Sub

As a workaround, I have set up a linked table in an Access Database and have used that to create a link between my Excel data table and the Oracle database, but ideally I want to remove the Access link as it seems like a step that could easily be lost/broken in the future if I am no longer in the organisation to manage it. This process does work though, without crashing Excel (runs in about 40 seconds).

I am running on 32-bit windows, but will soon be upgraded to 64-bit, so the code needs to work for both.

Any help would be greatly appreciated. Many thanks in advance.
 
Last edited:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
As an update, I have just tried running this on a 64-bit virtual machine and it does exactly the same thing - so it isn't to do with trying to run it on a 32-bit.
 
Upvote 0

Forum statistics

Threads
1,215,034
Messages
6,122,782
Members
449,095
Latest member
m_smith_solihull

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