force a command button to be pushed before exit

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
If you are referring to a Userform, you can use this
Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
   If CloseMode = vbFormControlMenu Then
      Cancel = True
      MsgBox "Please use the ""Close"" button.", vbCritical, "Illegal Exit"
   End If
End Sub
 
Upvote 0
You're more than welcome to use it, that's why we're here ;)
 
Upvote 0
this is what i have
i want the use to have to click commandbutton1 before exit.

ty



Private Sub CommandButton1_Click()


ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
filename:="C:\release" & Range("C2") & ".pdf", _
OpenAfterPublish:=False, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
Quality:=xlQualityStandard, _
From:=1, To:=2
End Sub




Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set r = Range("C2, n2")
For Each C In r
If C.Value = "" Then
MsgBox "Fill cells " & C.Address(0, 0)
Application.EnableEvents = False
C.Select
Application.EnableEvents = True
Exit For
End If
Next
End Sub


Private Sub commandbutto1(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the ""Close"" button.", vbCritical, "Illegal Exit"
End If
End Sub
 
Upvote 0
Is your button on a sheet or a userform?
 
Upvote 0
In that case can you answer JoeMo's questions in Post#2
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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