Bonjour,
Je fais une requete insert dans excel vba. Probleme jai limpression que la connection a la base de se ferme pas apres l' execution. quelel syntaxe je devrais utiliser pour cela? jai cherche pas mal de temps sans succes...
Merci!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Private Sub Insert_Click()
Range("A2:D3").Select
Selection.ClearContents
Range("A2").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER={MySQL ODBC 5.1 Driver};UID=root;;OPTION=35;PORT=3306;DATABASE=vb;SERVER=localhost;" _
, Destination:=Range("A2"))
.CommandText = Array("INSERT INTO tutorial VALUES ('" & Range("F1") & "', '" & Range("G1") & "', '" & Range("H1") & "', '" & Range("I1") & "')")
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=True
End With
End Sub |
je voudrais aussi savoir comment faire pour inserer la range F1 a F10.
si je met Range("F1:F10") dans
.CommandText = Array("INSERT INTO tutorial VALUES ('" & Range("F1") & "', '" & Range("G1") & "', '" & Range("H1") & "', '" & Range("I1") & "')")
ca ne fonctionne pas...
merci
Partager