I had the following formula in a cell on my WB01
='\000.000.0.000PublicDOCSHualley[FLUXO CAIXA HINDY - 108.xlsm]CONTAS MES'!BA80'
I’m trying to turn it into a function because I’m going to add a few more steps to make this formula more dynamic to meet a request, but I’m stuck because I can’t get the function to open the WB. My code so far (note that it won’t be my final code, I’ll do a lot more things still)
Function SearchCell(NameWB As String) As Variant
Dim DirBase As String
DirBase = "\000.000.0.000PublicDOCSHualley"
'Name WB in cell (A1 = "FLUXO CAIXA HINDY - 108.xlsm")
Dim DirFull As String
DirFull = DirBase & NameWB
Dim wb As Workbook
Dim ws As Worksheet
Dim SheetName As String
SheetName = "CONTA MES"
Dim CellLocation As String
CellLocation = "BA80"
Set wb = Workbooks.Open(DirFull, ReadOnly:=True)
Set ws = wb.Sheets(SheetName)
SearchCell = ws.Range(CellLocation).Value
wb.Close SaveChanges:=False
End Function
Is it possible to get the same result as the formula in a function in this case? For example, every time WB01 is opened, the formulas are updated, WB01 opens all the spreadsheets to which the formulas refer and updates their values. I would like to know if it is possible to get the same result with a function.
3