Problems with ADO copy from one excel file to another

dahlgrenen

New Member
Joined
Apr 22, 2012
Messages
9
Hi I am trying to use this code, but I get un error on the row
datConnection.Open "DBQ=" & strDB & amp, "," & strDriver & amp, ",UID=admin,"
I don't fully understand the code or what is wrong, could I get help?
The error says
'runtime error -2147467259(8004005}
[microsoft][ODBC driver Maneger]datasource not found and no default driver specified'

thankyou!


Sub ImporteraExcelTillExcel_ADO()

'--------------------------------------------------------------
'importerar data fr?n en extern Excelbok utan att ?ppna den
'--------------------------------------------------------------

'variabeldeklareringar
Dim datConnection As ADODB.Connection
Dim recSet As ADODB.Recordset
Dim recRubrik As ADODB.Field
Dim strDB, strSQL As String
Dim strDriver As String
Dim i As Long

's?kv?g till den externa Excelfilen
strDB = "C:\documents and setting\tcn0422\desktop\Dealer KPI Process Mapping report ATOC - 2010 - att arbeta med"


'uppkoppling
Set datConnection = New ADODB.Connection
Set recSet = New ADODB.Recordset
strDriver = "DRIVER=Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)"
datConnection.Open "DBQ=" & strDB & amp, "," & strDriver & amp, ",UID=admin,"

'SQL-f?rfr?gan
strSQL = "SELECT * FROM [Sheet1$B1:B10]" 'cellomr?de p? visst ark
'strSQL = "SELECT * FROM [Cellomr?desnamn]" 'f?r namngivna cellomr?den

'?ppnar ett "recordset"
recSet.Open strSQL, datConnection, adOpenStatic

'kopierar in ny data
ActiveSheet.Range("A2").CopyFromRecordset recSet

'kopierar kolumnrubriker
i = 1
For Each recRubrik In recSet.Fields
ActiveSheet.Cells(1, i) = _
recRubrik.Name: i = i + 1
Next recRubrik

'kopplar ned (viktigt!)
recSet.Close
datConnection.Close

'st?nger ned objekten (viktigt!)
Set recSet = Nothing
Set datConnection = Nothing

End Sub​
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
okey thank you for the help.
I find that one problem is that all the ”&amp” in the text should just be ”&". Now instead I have a problem a the row
recSet.Open strSQL, datConnection, adOpenStatic. But I don't know what.
 
Upvote 0

Forum statistics

Threads
1,216,459
Messages
6,130,758
Members
449,588
Latest member
accountant606

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