I'm working with code from Checking If A Sheet Exists In An External Closed Workbook
Function HasSheet(fPath As String, fName As String, sheetName As String)
On Error Resume Next
Dim f As String
f = "'" & fPath & "[" & fName & "]" & sheetName & "'!R1C1"
Debug.Print f
HasSheet = Not IsError(Application.ExecuteExcel4Macro(f))
If Err.Number <> 0 Then
HasSheet = False
End If
Debug.Print Err.Number
On Error GoTo 0
End Function
The variable f constructed from variables passed to the functions looks like this:
C:\Users\MyName\MyFolder[MyFile.xlsx]MySheet'!R1C1
When I pass filenames, containing the sheet I'm checking for, to the function the result is always the same:
HasSheet = False / Err.Number = 0