ActiveX Control Return Keypress MsgBox Loop

tomgreen1000

New Member
Joined
Jun 22, 2007
Messages
8
A simplified version of my problem. Consider a single command button on a blank worksheet. I want to be able execute the command button Click event with both the Return key and a mouse click. I want to be able to clear the message box with both the Return key and a mouse click. If I try to clear the message box with the Return key, it also executes the command button Click event again. So using the Return key to clear the message box puts you into a loop. Any ideas are greatly appreciated.

Thanks, Tom

In ThisWorkbook
Code:
Private Sub Workbook_Open()
Sheet1.Button1.Activate
End Sub
In Sheet1
Code:
Private Sub Button1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
    'Return is only key press that we care about
    Case vbKeyReturn
    Call Button1_Click
End Select
End Sub
Private Sub Button1_Click()
MsgBox "I am stuck in a loop when I use the Return key to clear this message box" & vbNewLine & "but everything is fine if I use a mouse click to clear this message box"
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You can control which button in a MsgBox is the default, so if the user presses the ENTER(Return) key the button you picked, as the default, is activated!

In this case I made the CANCEL button the Default.


Sub myBox()

MsgBox "Test Msg!", vbDefaultButton3 + vbInformation + vbYesNoCancel, "Test!"
End Sub
 
Upvote 0

Forum statistics

Threads
1,222,041
Messages
6,163,556
Members
451,844
Latest member
ddnndd1234

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top