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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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