In a standard module in a .xlam add-in I have the following UDF:
Public Function SheetExists(sheetToFind As String) As Boolean
SheetExists = False
Dim sht As Worksheet
For Each sht In Worksheets
If sheetToFind = sht.Name Then
SheetExists = True
Exit Function
End If
Next sht
End Function
When I call the function with =SheetExists() in a worksheet it works fine, as do all other UDF's in the add-in. However, when I call the function from a macro in a standard module in the personal workbook, I get an error. I call it as follows:
For i = 1 To iNumberOfSheets
If SheetExists(arrSheetList(i)) = True Then
arrSheetExists(i) = True
End If
Next i
I get the "Compile error: sub or function not defined" error directly on 'SheetExists' in the 2nd line.
Additionally, this hasn't given an error when I've been testing the wider macro for the last two days. It weirdly started after I created a new standard module today in the personal workbook to hold some public strings.
I haven't amended the UDF or any of the code around where I call it. I'm using Excel for Microsoft 365.
Any help would be greatly appreciated.