Set ObjWB = Workbooks.Open("c:\Test.xlsx")
If I used workbooks.open
command, that Excel workbook opens.
I need without open that Excel workbook to read the cell value.
Set ObjWB = Workbooks.Open("c:\Test.xlsx")
If I used workbooks.open
command, that Excel workbook opens.
I need without open that Excel workbook to read the cell value.
Run the Sub GetValue
after setting the parameters in ReadFromClosedWorkbook
(Workbook & Worksheet). You could pass either or both of them as arguments from the calling procedure.
Sub GetValue()
Debug.Print ReadFromClosedWorkbook("A1")
End Sub
Private Function ReadFromClosedWorkbook(Target As String) As Variant
Const WbFullName = "D:\My Documents\Your file name.xlsx"
Dim PathName As String
Dim WbName As String
Dim WsName As String
Dim Target As String
Dim Sp() As String
WsName = "My Worksheet's Name"
Sp = Split(WbFullName, "\")
WbName = Sp(UBound(Sp))
ReDim Preserve Sp(UBound(Sp) - 1)
PathName = Join(Sp, "\") & "\"
If Len(Dir(WbFullName)) Then
Target = "'" & PathName & _
"[" & WbName & "]" & WsName & _
"'!" & Range(Target).Address(True, True, xlR1C1)
ReadFromClosedWorkbook = ExecuteExcel4Macro(Target)
End If
End Function