The On Error Resume Next handles the error generated if the Match() fails, so it doesn't stop
i = -1
On Error Resume Next
i = Application.WorksheetFunction.Match(UCase(p.Name), aryFoldersToExclude, 0) ' <<<<<<<<<<<<<<<<<<<<<<<<<
On Error GoTo 0
isFolderExcluded = (i <> -1)
Basically it says the
1. Make i = -1 (I use that as a check value)
2. If there's any errors just keep on going
3. i = index of p.name in aryFoldersToExclude or an error if not found (but continue since Resume Next 'statement')
4. Turn off the 'Resume Next'
5. If i <> -1 (my check value) then the folder was in the list and IsFolderExcluded = True
5. If i = -1 (my check value) then the folder was NOT in the list and IsFolderExcluded = False
https://docs.microsoft.com/en-us/off...rror-statement
When there's a possibilty of getting an error, I typically will do it that way