Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Detect MsgBox keyUp

I have userform controls with Key events (down, press, up)
that run procedures if keycode 13 (enter) is pressed.

I may need to halt these proc's, first giving the user
some info in a msgbox. If the user closes the msgbox by
keying Enter, when enter is released the userform control
key event runs again, even a keydown event.

I could restrict the key event to say spacebar, but I want
to allow key Enter. I've tried various unsatisfactory
workarounds:

1. Timer on msgbox keydown to instigate a short delay
before the control can call the proc again. This works OK
but only if the user releases (msgbox) enter quickly.

2. Switch focus from the control, various problems with
this and also I want to end up with focus on the original
control.

I imagine others have run into this, but I have not found
anything searching this ng. So any solution much
appreciated.

TIA
Paul
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Detect MsgBox keyUp

Does the active message box become the Active Window" ? In this case
you could check for the Caption using something based on this :-

'== top ================================================
Declare Function GetActiveWindow Lib "user32" () As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As
Long

'========================
Sub GET_WINDOW_CAPTION()
'========================
MsgBox (ActiveWindowCaption)
End Sub

'-----------------------------------------
Function ActiveWindowCaption() As String
'-----------------------------------------
Dim strCaption As String
Dim lngLen As Long
'---------------------------------
strCaption = String$(255, vbNullChar)
lngLen = Len(strCaption)
If (GetWindowText(GetActiveWindow, strCaption, lngLen) 0) Then
ActiveWindowCaption = strCaption
End If
End Function
'== bottom ==================================


---
Message posted from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Detect MsgBox keyUp

Hi Brian,

Does the active message box become the Active Window" ?

It is whilst being displayed, but it closes on Keydown
Enter.

For my purposes it would be more convenient if it closed
with Keyup, like it does if the user presses spacebar.

To side track, I could have phrased my original question
and subject better, namely:
Detect if user closed msgbox with key Enter, if so prevent
or early exit Key events in my controls (with focus) until
user has released Enter.

In case relevant my controls also have mouse events, but
not Click events as these would also be activated with key
Enter.

Your suggestion looks promising but I'm not sure when and
where to return and compare "ActiveWindowCaption" and
presumably set a flag. Sorry to ask but if you think this
will resolve my problem could you point me how to
implement!

Thanks,
Paul

-----Original Message-----
Does the active message box become the Active Window" ?

In this case
you could check for the Caption using something based on

this :-

'== top ================================================
Declare Function GetActiveWindow Lib "user32" () As Long
Declare Function GetWindowText Lib "user32"

Alias "GetWindowTextA" _
(ByVal Hwnd As Long, ByVal lpString As String, ByVal cch

As Long) As
Long

'========================
Sub GET_WINDOW_CAPTION()
'========================
MsgBox (ActiveWindowCaption)
End Sub

'-----------------------------------------
Function ActiveWindowCaption() As String
'-----------------------------------------
Dim strCaption As String
Dim lngLen As Long
'---------------------------------
strCaption = String$(255, vbNullChar)
lngLen = Len(strCaption)
If (GetWindowText(GetActiveWindow, strCaption, lngLen)

0) Then
ActiveWindowCaption = strCaption
End If
End Function
'== bottom ==================================


---
Message posted from http://www.ExcelForum.com/

.

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
need to detect syntax in value J.Parker Excel Discussion (Misc queries) 1 February 13th 10 05:09 AM
How to detect #N/A and return 0? Eric Excel Discussion (Misc queries) 2 May 30th 07 06:12 AM
How to detect changes in a column? inomata Excel Discussion (Misc queries) 0 December 14th 05 08:26 PM
detect worksheet mike allen Excel Programming 2 October 28th 03 10:33 PM
How to detect a col/row deletion? Mauricio Villada Excel Programming 1 September 15th 03 08:53 PM


All times are GMT +1. The time now is 10:17 PM.

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

About Us

"It's about Microsoft Excel"