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 32 33 34 35 36 37 38 39 40 41
|
Dim cnBat As ADODB.Connection
Set cnBat = New ADODB.Connection
Dim strConn As String
strConn = "PROVIDER=SQLOLEDB;"
strConn = strConn & "DATA SOURCE=10.11.7.10;............"
cnBat.Open strConn
cnBat.CommandTimeout = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2
Worksheets("resultat").Range("A4:S10000").ClearContents
Set f = fso.OpenTextFile(chemin & "\sql\requete.sql", ForReading)
une_variable = f.ReadAll
f.Close
Dim rsBat As ADODB.Recordset
Set rsBat = New ADODB.Recordset
With rsBat
.ActiveConnection = cnBat
.Open une_variable
DerniereLigne = Range("A6000").End(xlUp).Row + 1
MsgBox (DerniereLigne)
Worksheets("resultat").Range("A" & DerniereLigne).CopyFromRecordset rsBat
.Close
End With
cnBat.Close
Set rsBat = Nothing
Set cnBat = Nothing |
Partager