Is there anything like Application.IsError(MissingObject) that can return false for a bad reference?
I have a macro which uses a UserForm. It just pops open with two buttons, the user clicks one and the macro resumes. This macro is run dozens of times and the file is left open for hours. For one reason or another, the UserForm sometimes stops existing and the macro gives the error on the line that opens the UserForm. I know the UserForm is the issue because if I click on it in the editor after getting this error, the application crashes.
I am using Excel 2007, so the real fix is probably to upgrade to something made this decade, but my work-around is just to exit the macro and reopen the file. Is there any method to allow Excel to recognize when the UserForm stops existing?
You could go through the VBComponents in the workbook and see if the userform is there.
Here's a function that will search by name.
Function IsUserFormThere(strFormName As String) As Boolean
Dim comp As Variant
For Each comp In ThisWorkbook.VBProject.VBComponents
If comp.Name = strFormName Then
IsUserFormThere = True
Exit Sub
End If
Next comp
End Function
This function could be called when the button(s) are presses and if the userform isn't found code execution could be stopped and the user informed what to do next.