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
| Sub connect_bsb()
Dim my_connect As New ADODB.Connection
Dim my_rec As New ADODB.Recordset
Worksheets("feuil1").Activate
Set sh1 = Excel.Worksheets(1)
Range("a1").Select
my_connect.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER="";DATABASE=bc;UID=root;PWD="
my_connect.Open
Sql = "select * from agences"
my_rec.CursorLocation = adUseServer
my_rec.Open Sql, my_connect
my_rec.MoveFirst
c = 1
Do Until my_rec.BOF Or my_rec.eof
sh1.Cells(c, 1).Value = my_rec.fields(1)
' sh1.Cells(c, 2).Value = my_rec.fields(2)
' sh1.Cells(c, 3).Value = my_rec.fields(3)
' sh1.Cells(c, 4).Value = my_rec.fields(4)
' sh1.Cells(c, 5).Value = my_rec.fields(5)
' sh1.Cells(c, 6).Value = my_rec.fields(6)
' sh1.Cells(c, 7).Value = my_rec.fields(7)
my_rec.MoveNext
c = c + 1
If my_rec.eof Then
my_rec.MoveFirst
Exit Sub
End If
Loop
my_connect.Close
End Sub |