Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Which activeX control currently has the focus?

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?)

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Which activeX control currently has the focus?

Hi Peter

Thanks for the suggestion - I figured there wasn't a 'real' way to do it :(

What about creating a global variable, and in the GotFocus/LostFocus events I could save/clear the name of the current control. Is that reasonable?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Which activeX control currently has the focus?


"Khuli" wrote in message
Hi Peter

Thanks for the suggestion - I figured there wasn't a 'real' way to do it
:(

What about creating a global variable, and in the GotFocus/LostFocus
events I could save/clear the name of the current control. Is that
reasonable?


That's virtually what the example does, adds or clears the name at module
level in the sheet "class" module. If you prefer it fully global declare
the variable in a normal module, say

Public gsActiveAX As String

FWIW you could save/destroy an object reference, but for something like this
I'd prefer to store the name and recreate the reference with the name.

Peter T


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Which activeX control currently has the focus?

Hi Peter

Thanks for the suggestion - I figured there wasn't a 'real' way to do
it :(

What about creating a global variable, and in the GotFocus/LostFocus
events I could save/clear the name of the current control. Is that
reasonable?


Optionally...

Public gcboActive As Object '//in a standard module

Then in the sheet code module:
Private Sub ComboBox1_GotFocus()
Set gcboActive = Me.ComboBox1
End Sub
Private Sub ComboBox1_LostFocus()
Set gcboActive = Nothing
End Sub

Then ref it in code like this...

Sub DoThis()
If gcboActive = Nothing Then Exit Sub
If gcboActive.Text = <string Then...
OR
If gcboActive.ListIndex = <number Then...
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set focus on an ActiveX ListBox Rob Flott Excel Programming 7 June 22nd 12 06:10 PM
2007 Form Control/ActiveX Control font difference Nikko963 Excel Discussion (Misc queries) 0 April 15th 09 04:21 PM
ActiveX Combo Box Focus CraigB[_2_] Excel Programming 0 February 23rd 09 05:04 PM
publish activeX combobox and other activeX control irene c Excel Programming 0 March 19th 07 08:19 AM
Set Focus Problem for textbox control on multipage control ExcelDeveloperSPR Excel Programming 1 July 16th 04 08:54 PM


All times are GMT +1. The time now is 09:46 AM.

Powered by vBulletin® Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright 2004-2023 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"