force a command button to be pushed before exit

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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,223,774
Messages
6,174,453
Members
452,565
Latest member
curtoliver68

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