Userform default command button doesn't change

jasonfish11

Board Regular
Joined
May 14, 2015
Messages
56
Hi all,
I can't find a solution to the problem I'm having anywhere.

I built a simple userform that will appear when a workbook is opened.
There is a warning notice and 2 command buttons "Continue" and "Leave/Exit"

Below is the coding for both.

The issue I'm having is I would like the "Continue" button to be the default so that if someone just reads it and hits enter the userform closes but the workbook stays open. I can see in the properties that the "Continue" button is default=True and the "Leave/Exit" button is default=false. The issue is when I hit enter in this userform the "leave/exit" macro runs. Also the "Leave/Exit" button is the one framed with the dots (indicating it's the default). I tried switching the default to "Leave/Exit" in properties and nothing changed.

I've attached an image of the properties.

VBA Code:
Private Sub ContinueCommand_Click()

Unload ChromeWarning

End Sub

Private Sub LeaveCommand_Click()

Unload ChromeWarning
ActiveWorkbook.Close SaveChanges:=False

End Sub

Thanks in advance.
 

Attachments

  • properties.png
    properties.png
    83.6 KB · Views: 16

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try the following:

VBA Code:
Private Sub UserForm_Initialize()
    ContinueCommand.SetFocus
End Sub
 
Upvote 0
Try the following:

VBA Code:
Private Sub UserForm_Initialize()
    ContinueCommand.SetFocus
End Sub


This worked, I still don't understand why the default isn't working. I've built dozens of userforms before and never ran into this issue (and haven't found anything online with similar issues).
 
Upvote 0
Alternately just change the TabIndex property of the button to 0
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,685
Members
449,117
Latest member
Aaagu

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