View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
German[_2_] German[_2_] is offline
external usenet poster
 
Posts: 5
Default Export Data from Excel to SQL

I am trying to export a large about of data from excel to sql, this
doesn't seem to work, any suggestion. I tried doing it one line at a
time but it was very slow.

Sub test_database_export()
Dim db As database
Dim sqlstring1 As String
Dim data() As Variant

data() = Range("A2:D18933").Value

Application.ScreenUpdating = False

Set db = OpenDatabase("", True, False,
"ODBC;DSN=sqlserver;uid=xxx;pwd=xxx")
sqlstring1 = "INSERT INTO [Sheet3$] (Scenario,Period,Block,Price)
VALUES " & data() & ")"
db.Execute (sqlstring1)
db.Close
Set db = Nothing

Application.ScreenUpdating = True

End Sub

Thanks in adavance.

German