1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| Sub export_vers_tdb_oi()
Dim dernlign, dernlignsource As Integer
Dim Cn, cndest As ADODB.Connection
Dim Rst, rst2 As ADODB.Recordset
Dim propriete As Properties
dim texte_SQL, texte_sql2 As String
Dim i, j As Integer
Application.DisplayAlerts = False
set Cn = New ADODB.Connection
'On établit la connection avec la base TDB_OI
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & ThisWorkbook.Path & "\" & ThisWorkbook.Name & ";Extended Properties=Excel 8.0;"
requête SQL
texte_SQL = "Select * from [temp_eotp$]"
Set Rst = New ADODB.Recordset 'Création objet rst( permettant d'interroger la base)
Set Rst = Cn.Execute(texte_SQL, dbOpenForwardOnly, dbReadOnly) 'Exécution requête SQL
Set cndest = New ADODB.Connection
With cndest
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" _
& chemin_base & ";Extended Properties=""Excel 12.0;HDR=YES;"""
.Open
End With
Set rst2 = New ADODB.Recordset 'Création objet rst( permettant d'interroger la base)
texte_sql2 = "Select * from [" & onglet_source & "$] "
rst2.Open texte_sql2, cndest, adOpenKeyset, adLockOptimistic
dernlignsource = Sheets("temp_eotp").Cells(1000000, 1).End(xlUp).Row
j = 1
Do While Not j > dernlignsource
On Error Resume Next
rst2.AddNew
For i = 0 To rst2.Fields.Count
rst2.Fields(i) = Rst.Fields(i).Value
dernlign = dernlign + 1
Next i
j = j + 1
Rst.MoveNext
Loop
rst2.Update
Rst.Close 'On détruit l'objet rst
Set Rst = Nothing
rst2.Close 'On détruit l'objet rst
Set rst2 = Nothing
Cn.Close 'On ferme la connection
Set Cn = Nothing |
Partager