Sub ADOExcelSQLServer()
Dim Cn As ADODB.Connection
Dim Server_Name As String
Dim Database_Name As String
Dim User_ID As String
Dim Password As String
Dim SQLStr As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim Num As String
Server_Name = "127.0.0.1"
Database_Name = "base"
User_ID = "root"
Password = "m02pas"
'------------- Num est le critere de recherche dans ma base de donnée MySQL
Num = 1022
SQLStr = "SELECT numero FROM table01 WHERE numero LIKE '" & Num & "%'"
Set Cn = New ADODB.Connection
Cn.Open "Driver={MYSQL ODBC 8.0 Unicode Driver};Server=" & Server_Name & ";Database=" & Database_Name & ";Uid=" & User_ID & ";Pwd=" & Password & ";"
rs.Open SQLStr, Cn, adOpenStatic
'-----------------Affichage des resultats dans la feuil 2 de mon classeur Excel
With Worksheets("Feuil2").Range("a1:z500")
.ClearContents
.CopyFromRecordset rs
End With
rs.Close
Set rs = Nothing
Cn.Close
Set Cn = Nothing
End Sub