How to promt users to save their work?

  • Thread starter Thread starter shirley
  • Start date Start date
S

shirley

For my program, all new entries are in red. When the user clicks th
close button of the workbook, i want to do a msgbox to prompt users t
save. when they save, the font becomes black. this way, when they ope
the workbook again, they cannot make changes to the entries. attache
is the coding. I dont think my code is working because when the clos
button is pressed, its the default excel msgbox.

Sub ActiveWorkbook_beforeClose()
Dim Msg, Style, Title, Response

Msg = "Are you sure you want to exit? No changes are allowed afte
closing of the workbook."

Style = vbYesNo + vbQuestion
Title = "Important!"

Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then
ActiveWorkbook.Save


Else: End If .
End Su
 
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
if SaveAsUI then
cancel = true
End if
End Sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Msg, Style, Title, Response

Msg = "Are you sure you want to exit? No changes are allowed after closing
of the workbook."

Style = vbYesNo + vbQuestion
Title = "Important!"
Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then
'code to change font color
Application.EnableEvents = False
ActiveWorkbook.Save
Application.EnableEvents = True

Else:
Cancel = True
End If
End Sub

Untested.
 
Back
Top