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
| Function LireCellule_ClasseurFerme( _
Chemin As String, _
Fichier As String, _
Feuille As String, _
Cellule As Variant) As Variant
Application.Volatile
Dim Source As Object, Rst As Object, ADOCommand As Object
Dim Cible As String
Feuille = Feuille & "$"
Cible = Cellule.Address(0, 0, xlA1, 0) & ":" & _
Cellule.Address(0, 0, xlA1, 0)
Set Source = CreateObject("ADODB.Connection")
Source.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Chemin & "\" & Fichier & _
";Extended Properties=""Excel 8.0;HDR=No;"";"
Set ADOCommand = CreateObject("ADODB.Command")
With ADOCommand
.ActiveConnection = Source
.CommandText = "SELECT * FROM [" & Feuille & Cible & "]"
End With
Set Rst = CreateObject("ADODB.Recordset")
'1 = adOpenKeyset, 3 = adLockOptimistic
Rst.Open ADOCommand, , 1, 3
Set Rst = Source.Execute("[" & Feuille & Cible & "]")
LireCellule_ClasseurFerme = Rst(0).Value
Rst.Close
Source.Close
Set Source = Nothing
Set Rst = Nothing
Set ADOCommand = Nothing
End Function |
Partager