Auto-save worksheet on close?

O

oystlars

Hello!

At work we have a worksheet that is always open. A lot of people are
adding data to the file (on only one computer). But we have a problem;
people are shutting down excel and pressing "no" on the "Do you want to
save changes"-notification.

So;
How could I disable the notification, and instead put on a macro like
this;

Private Sub Worksheet_Close()
Worksheet.Save
End Sub
________________________________

Well, I'm no programmer, so it's surely not right, but how could I
easily do what I want?

Thanks.
Øystein
 
R

Roger Govier

Hi
You could enter something like the following in the Workbook module

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayAlerts = False
If ActiveWorkbook.ReadOnly = True Then
ActiveWorkbook.Close SaveChanges:=False
Exit Sub
Else
ActiveWorkbook.Close SaveChanges:=True
End If
Application.DisplayAlerts = True
End Sub

This will check to see that the file has not been opened as Read Only,
and if not, it will save it before closing regardless of any choices
made by the user.
 
Top