Recently, I had the need to find the active control on a UserForm for a dialog box I was creating for Word 2003. The problem was that most of my controls were on a MultiPage control. Whenever the active control was on the MultiPage, UserForm.ActiveControl returned the MultiPage, not the control I wanted.
My solution was to write the following function, GetActiveControl which would essentially ignore MultiPages and Frames to return the “real” active control:
Public Function GetActiveControl(ByRef Source As UserForm) As Control
Dim Ctl As Control
Set Ctl = GetSubActiveControl(Source.ActiveControl)
Set GetActiveControl = Ctl
End Function
Private Function GetSubActiveControl(Ctl As Control) As Control
Dim CtlType As String
CtlType = TypeName(Ctl)
Select Case CtlType
Case "MultiPage"
Set Ctl = Ctl.SelectedItem.ActiveControl
Set Ctl = GetSubActiveControl(Ctl)
Case "Frame"
Set Ctl = Ctl.ActiveControl
Set Ctl = GetSubActiveControl(Ctl)
End Select
Set GetSubActiveControl = Ctl
End Function
As you can see, I use a private recursive function to do the real work of finding the control. I suppose I could have done it some other way, but this seemed to be the most straightforward.
One commentIs this thing still on? Seems like I haven’t updated in ages. My D&D campaign is kaput, so I am trying to figure out what exactly to do with the site.
Anyway, during my never-ending voyages through the web, I came across the following gem. I’ve seen PCs do some stupid things, but never quite like this. It is about 10 years old, but I had never seen it before so I’d thought I’d share:
Comments Off on Most Stupid Gamers Ever