Function pathEx(path As String) As Boolean
On Error Resume Next
pathEx = dir(path, vbDirectory) <> vbNullString
End Function
Function getFile(path As String, Optional tst As Boolean) As String
On Error GoTo exitFunc
tst = False
If Right$(path, 1) = "\" Then GoTo exitFunc
getFile = Right$(path, Len(path) - InStrRev(path, "\"))
tst = True
exitFunc:
End Function
Function getFold(path As String, Optional tst As Boolean) As String
tst = False
On Error GoTo exitFunc
getFold = Left$(path, InStrRev(path, "\") - 1)
tst = True
exitFunc:
End Function
'got this from cPearson
Function getValue(fullPath As String, wsName As String, _
rngAd As String, _
Optional tst As Boolean) As Variant
' Retrieves a value from a closed workbook
tst = False
On Error GoTo exitFunc
' Make sure the file exists
If Not pathEx(fullPath) Then getValue = "": Exit Function
' Make sure is an excel document
If Not fullPath Like "*.xl*" Then Exit Function
' Execute an XLM macro
getValue = ExecuteExcel4Macro("'" & getFold(fullPath) & "\[" & getFile(fullPath) & "]" & wsName & "'!" & _
Range(rngAd).Cells(1).Address(, , xlR1C1))
' No error so tst=true:
tst = True
exitFunc:
End Function