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
| Private Sub CommandButton1_Click()
Dim Conn As ADODB.Connection
Dim rsT As ADODB.Recordset
Dim Fichier As String, Direction As String, rSQL As String
Direction = ThisWorkbook.Path
Fichier = "maBase.xls"
Set Conn = New ADODB.Connection
With Conn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & Direction & "\" & Fichier & _
";Extended Properties=Excel 8.0;"
.Open
End With
rSQL = "SELECT * FROM [Feuil1$] WHERE [nomColonne46] ='IN' AND [nomColonne47] ='N'"
Set rsT = New ADODB.Recordset
With rsT
.ActiveConnection = Conn
.Open rSQL, , adOpenKeyset, adLockOptimistic, adCmdTableDirect
End With
Range("A1").CopyFromRecordset rsT
rsT.Close
Conn.Close
End Sub |
Partager