View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default How to promt users to save their work?

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.

--
Regards,
Tom Ogilvy

"shirley " wrote in message
...
For my program, all new entries are in red. When the user clicks the
close button of the workbook, i want to do a msgbox to prompt users to
save. when they save, the font becomes black. this way, when they open
the workbook again, they cannot make changes to the entries. attached
is the coding. I dont think my code is working because when the close
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 after
closing of the workbook."

Style = vbYesNo + vbQuestion
Title = "Important!"

Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then
ActiveWorkbook.Save


Else: End If .
End Sub


---
Message posted from http://www.ExcelForum.com/