Mouse Click only for MsgBox Buttons

Big Lar

Well-known Member
Joined
May 19, 2002
Messages
557
Is there vbcode that prevents the Enter key from executing the MsgBox buttons?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You can use the status bar to show messages that require no input from the user.

Example:
Code:
Application.Statusbar = "Uploading...Please wait..."
Just be sure when your routine is through that you set the status bar back to false (which essentially "clears" or "resets" it:
Code:
Application.StatusBar = False
 
Upvote 0
Thanks, xenou...
But I rethought the process.

I have an “EXIT” CommandButton on a UserForm that quits the application. It’s possible that a user may accidently click the button…losing all data entry!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
So, I added a MsgBox to warn of the impending data loss. I also set the button’s tab stop to false which prevents unexpected Enter key from “clicking” the button.<o:p></o:p>
<o:p></o:p>
Well…One of my users clicked on the Exit button to see what would happen and then hit the enter key! The application quit…all the data entry was lost…and it was my fault!<o:p></o:p>
<o:p></o:p>
So, I added a second MsgBox to warn the user twice. I also set the button focus to Button 2 so that click/enter/enter returns the user to the UserForm. I think that will solve my problem.<o:p></o:p>
<o:p></o:p>
Code:
[FONT=Verdana]Private Sub CommandButton2_Click()<o:p></o:p>[/FONT]
[FONT=Verdana]<o:p></o:p>[/FONT]
[FONT=Verdana]If MsgBox(Prompt:="ARE YOU SURE?    THIS CANNOT BE UNDONE!" & vbCrLf & "Click Cancel to continue data entry." & vbCrLf & "Your entries will be LOST if you click OK!", Buttons:=vbOKCancel + vbDefaultButton2, Title:="CAREFUL! CAREFUL!") = vbOK Then<o:p></o:p>[/FONT]
[FONT=Verdana]If MsgBox(Prompt:="ONE LAST CHANCE!" & vbCrLf & "ALL ENTRIES WILL BE LOST!" & vbCrLf & "Click Cancel to return to data entry." & vbCrLf & "If you click OK your entries will be DISCARDED!", Buttons:=vbOKCancel + vbDefaultButton2, Title:="ONE LAST CHANCE") = vbOK Then<o:p></o:p>[/FONT]
[FONT=Verdana]<o:p></o:p>[/FONT]
[FONT=Verdana]Application.DisplayAlerts = False<o:p></o:p>[/FONT]
[FONT=Verdana]Application.Quit<o:p></o:p>[/FONT]
[FONT=Verdana]End If<o:p></o:p>[/FONT]
[FONT=Verdana]End If<o:p></o:p>[/FONT]
[FONT=Verdana]<o:p></o:p>[/FONT]
[FONT=Verdana]Exit Sub<o:p></o:p>[/FONT]
[FONT=Verdana]End Sub<o:p></o:p>[/FONT]
<o:p></o:p>
 
Upvote 0
If you set it to default button 3, neither OK nor Cancel will be the default.
Code:
MsgBox "Are you sure?", vbOKCancel + vbDefaultButton3
I don't know why this doesn't work with vbOKOnly.
 
Upvote 0
I'd probably just use an warning:

Code:
Dim rsp As Integer
rsp = Msgbox "Canceling will exit without saving your work.  " _
    & vbNewLine & "Exit anyway?", vbYesNo

If rsp = vbYes Then
    '//Continue with Cancel Operations
Else
    '//Return to active form
End If
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,290
Members
452,902
Latest member
Knuddeluff

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