Currently I make a code in a class module which work as expected :
Private Sub bt_Click()
Dim oObj As Object
If UserForms.Count = 0 Then
Set oObj = ActiveSheet
Else
For Each uf In VBA.UserForms: Set oObj = uf: Next uf
End If
Debug.Print oObj.Name
End Sub
If there's no UserForm seen in the active sheet, then the oObj is the activesheet - else the oObj is the only one Userform seen in the active sheet.
Curious if there is a syntax to set the oObj as the only one Userform seen in the active sheet without the loop, something like set oObj = TheOnlyOneUserformSeenInThisPage - I googled the internet and search this site, but I can't find the same question like mine.
What I've tried so far (by guessing) : set oObj = UserForm(1) but before the sub run it already throw me an error : Sub or Function not defined with the UserForm at UserForm(1) is highlighted in blue.
So my question is :
what is the syntax to set the oObj which something like set oObj = TheOnlyOneUserformSeenInThisPage ?
Any kind of response would be greatly appreciated.
Thank you in advanced.