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
| Sub enregistrement nouvelle donnee()
Dim Cn As ADODB.Connection
Dim Cd As ADODB.Command
Dim Rst As ADODB.Recordset
Dim Fichier As String
Dim laudit As Integer
Dim NDocA4 As Integer
laudit = 2
'collecte des infos résultats audit dans feuille data
NDocA4 = Feuil6.Cells(33, "a")
'les données à inserer
Fichier = "G:\toto.xls"
Set Cn = New ADODB.Connection
Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Fichier & ";" & _
"Extended Properties=""Excel 8.0;HDR=No;"";"
Set Cd = New ADODB.Command
Cd.ActiveConnection = Cn
Feuil13.Activate
'boucle while pour connaitre la ligne libre dans la feuil etat
Do While Not IsEmpty(Feuil13.Cells(laudit, "a"))
laudit = laudit + 1
Loop
Feuil13.Cells(laudit, "a") = NDocA4
Set Rst = New ADODB.Recordset
Rst.Open Cd, , adOpenKeyset, adLockOptimistic
Rst(0).Value = "Donnée test"
Rst.Update
Cn.Close
Set Cn = Nothing
Set Cd = Nothing
Set Rst = Nothing
End Sub |
Partager