vbOKCancel use question

wpryan

Well-known Member
Joined
May 26, 2009
Messages
534
Office Version
  1. 365
Platform
  1. Windows
Hi All, I am using the following code to alert a user that data entry which is required to generate the filename hasn't been made, and when OK is clicked a dialog box appears showing the filename which defaults to '.xls.
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
 
Dim NameToSaveAs As String
Dim CurrentBookName As String
Dim NameForLabel As String
Dim RangeForLabel As String
Dim FSR As String
Application.EnableEvents = False 'Needed to stop infinite loop on save
If FSR = "" Then
    MsgBox "WARNING: There is no FSR No. FSR number is required."
End If
CurrentBookName = ActiveWorkbook.Name
FSR = Range("FSR_NO").Value
NameToSaveAs = FSR & ".xls"
Application.Dialogs(xlDialogSaveAs).Show NameToSaveAs
EndOfSub:
Application.EnableEvents = True
Cancel = True
End Sub

I want to add a 'cancel' button to the message box that will stop the close and save process. How can this be done?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Perhaps:-
Code:
If FSR = "" Then
    If MsgBox("WARNING: There is no FSR No. FSR number is required.", vbOKCancel + vbQuestion, "Accept/Reject") = vbOK Then
        MsgBox "Do Code Here,if Accepted"
    End If
End If
Mick
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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