Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to promt users to save their work?

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

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
close workbook without saving or promt to save ATVNSHANE Excel Discussion (Misc queries) 3 February 4th 10 03:57 PM
Users must save as new spreadsheet springtimetigger Excel Worksheet Functions 3 November 3rd 08 10:52 PM
Save in Excel several users server Jan Excel Discussion (Misc queries) 0 February 14th 06 05:25 PM
Is there away to keep "auto save" from jumping to the first work sheet in the work book? Marc New Users to Excel 2 April 21st 05 01:27 AM
simultaneously work in a work book with other users Sweets Excel Discussion (Misc queries) 1 April 18th 05 07:35 PM


All times are GMT +1. The time now is 06:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"