View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_7_] Peter T[_7_] is offline
external usenet poster
 
Posts: 162
Default Which activeX control currently has the focus?

"Khuli" wrote in message

I have a worksheet with a dozen or so activex comboboxes on.

How can I tell in vba which one is currently active? (i.e. which one has
the cursor in?)


I don't think there is a direct way, like say returning ActiveControl on a
form.

Maybe you could adapt something like the following though it'd mean trapping
focus for all your controls, error handling, and what happens when the sheet
is activated or deactivated which I didn't look at

, in the worksheet module
Private msActiveAX As String

Private Sub ComboBox1_GotFocus()
msActiveAX = "ComboBox1"
End Sub
Private Sub ComboBox1_LostFocus()
msActiveAX = ""
End Sub

Sub test()
Dim ole As OLEObject
Dim oleCbo As MSForms.ComboBox
Debug.Print msActiveAX
If Len(msActiveAX) Then
Set ole = Me.OLEObjects(msActiveAX)
If InStr(1, ole.progID, "ComboBox") Then
Set oleCbo = ole.Object
End If
End If
End Sub

Unfortunately Got & LostFocus are not exposed with WithEvents

Peter T