Sunday, September 10, 2006

Get The Active Control In A UserForm

— Matt Harris @ 11:05 am

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 comment
Saturday, May 28, 2005

Excel Name Manager

— Matt Harris @ 3:41 pm

One of the links in the Heroforge Mailing List referred to this Excel Name Manager. It is an add-in for Excel that makes is much easier to sort through and manage named ranges in Excel. I have barely tried it out, but it appears to be really good.

There are also a lot of other Excel utilities on their download page, but I haven’t checked them out yet.

Comments Off on Excel Name Manager

  • 1530s Europe Campaign (15)
  • Books (7)
  • BTVS & Angel (24)
  • Cormaria (22)
  • Doctor Who (1)
  • Fanfiction Recs (19)
  • General (36)
  • Harry Potter (19)
  • Humor (16)
  • Java (1)
  • Microsoft Office (2)
  • Northridge Pathfinder (24)
  • (1)
  • Pathfinder (30)
  • Politics (4)
  • Programming (6)
  • Programs (5)
  • Reviews (2)
  • Role-Playing Games (D&D et. al.) (85)
  • Science (1)
  • Site News (120)
  • Smallville (2)
  • Stargate (2)
  • Tips (4)

  • Powered by Wordpress