1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Sub Write2XL()
Dim Cnn As Object
Set Cnn = CreateObject("ADODB.Connection")
repertoire = ThisWorkbook.Path & "\"
Fichier = repertoire & "ADOsource.xlsx"
Cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & Fichier & ";" & _
"Extended Properties=Excel 12.0;"
'oCn.Execute "Insert Into [Feuil1$] (texte) Values('mon texte')"
Dim cm As New ADODB.Command
With cm
.ActiveConnection = Cnn
.CommandText = "INSERT INTO [Feuil1$] ([texte]) Values (?)"
.CommandType = adCmdText
Set Pm = .CreateParameter("@texte", adLongVarChar, adParamInput, 30000, Workbooks("Ajout enregistrements.xls").Sheets("feuil1").Cells(2, 3))
.Parameters.Append Pm
'On Error Resume Next
.Execute
Debug.Print Err.Description
End With
Cnn.Close
End Sub |