I have a few closed Excel workbooks, which I would be willing to access with =INDEX(MATCH) without openning them.
Unfortunately, I want to refer to them indirectly, thus based on the current sheet I am in.
E.g. - if I am in sheet -> then file path:
AAB -> 'C:\Users\vityata\Desktop\[AAB]Test'!$A:E
BBC -> 'C:\Users\vityata\Desktop\[BBC]Test'!$A:E
It seems like a trivial task, but the only options to do something like this seem to be the following:
- Open the sheet and then use
Indirect()(but I do not want to open the sheet) - Use VBA code (but it should be somehow reusable and really last resort)
- Use data connection (I do not want it)
- Use
INDIRECT.EXT(but I do not want 3. party add-ins)
I have checked similar problems here: How to referencing value in closed excel workbook by formula incl. variable sheetname? but the first solution is rather too colmplicated to do it.
Any new ideas or best practices?
Update So far I have achieved the following with VBA (although I would love to have a non-VBA solution):
Option Explicit
Public Sub VlookupClosedWb(Optional strLookFor As String = "Erteilung Baugenehmigung", _
Optional strSheet As String = "APF", _
Optional lngColIndex As Long = 2)
Dim strRange As String
strRange = "'" & ThisWorkbook.Path & "\[" & strSheet & ".xlsx]" & "Monatsbericht'!$A:$E"
ActiveCell.Formula = "=VLOOKUP(""" & strLookFor & """," & strRange & "," & lngColIndex & ",0)"
End Sub
Public Function fVlookupClosedWb(Optional strLookFor As String = "Erteilung Baugenehmigung", _
Optional strSheet As String = "APF", _
Optional lngColIndex As Long = 2)
Dim strRange As String
strRange = "'" & ThisWorkbook.Path & "\[" & strSheet & ".xlsx]" & "Monatsbericht'!$A:$E"
fVlookupClosedWb = WorksheetFunction.VLookup(""" & strLookFor & """, " & strRange & ", " & lngColIndex & ", 0)
End Function
Long story short - the Sub works as expected, providing exactly what I want in the active cell. The Function does not work. Any ideas how to make it work? I suppose that it does not work, because I am abusing a bit WorksheetFunction.VLookup, but I cannot pass a range without openning the other workbook. Ideas?
VBAand it was actually my last resort... - VityataIndirectthan doing this. - Vityata