Message Box before save

greatcookies

Board Regular
Joined
Sep 25, 2005
Messages
187
I have an excel spreadsheet that I need a message box to appear upon saving. The message box is simply a remainder and they could click ok to proceed with save. What code is needed to make this happen.

Thanks!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
This will work but i would think you might want to allow them to cancel the save process but if you just want to show a box before it saves this works.

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
MsgBox "You are about to save this file.", vbInformation
End Sub
 
Upvote 0
if you hit ALT + F11 then double click on thisworkbook and paste this code.

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim str As String
    
    str = MsgBox("Are you sure you want to save?", vbYesNo)
    
    If str = vbNo Then
        Cancel = True
    End If

End Sub

This will prompt them and if the hit no it will stop the save.
Good luck
 
Upvote 0

Forum statistics

Threads
1,203,378
Messages
6,055,087
Members
444,761
Latest member
lneuberger

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