[Excel] Referencia externa: libros cerrados
Resuelto
Sylvain
-
schoret Mensajes publicados 6 Estado Miembro -
schoret Mensajes publicados 6 Estado Miembro -
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 = , 3 =
Rst.Open
ADOCommand, , adOpenKeyset, adLockOptimistic
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
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 = , 3 =
Rst.Open
ADOCommand, , adOpenKeyset, adLockOptimistic
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
5 respuestas
-
Sub LireFichierFermé() Dim NomFichier As String Dim Chemin As String Dim Formule As String ActiveSheet.Range("A1").ClearContents Chemin = "D:\Temp\" NomFichier = "Classeur_à_lire.xls" Formule = "='" & Chemin & "[" & NomFichier & "]Feuil1" & "'!" & "A1" ActiveSheet.Range("A1").Formula = Formule ActiveSheet.Range("A1").Value = ActiveSheet.Range("A1").Value End Sub