Jarlisle
12-06-2010, 10:09 AM
I have the following code run when the file is closed:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ScreenUpdating = False
Dim objSheet As Worksheet
'Protecting all worksheets with password
For Each objSheet In Worksheets
If objSheet.ProtectContents = False Then objSheet.Protect "NESAFE", True, True, True, , , , , , , , , , , True, True
Next objSheet
Sheet9.Visible = False
Sheet8.Visible = False
Sheet3.Visible = False
Sheet4.Visible = False
Sheet1.Visible = False
Sheet10.Visible = False
Sheet5.Select
Range("A1").Select
Application.ScreenUpdating = True
Sheet5.Select
Range("A1").Select
ActiveWorkbook.Save
End Sub
Is there a way to only have this run if the file is in edit mode instead of read-only? Also, when it saves at the end it seems to remove my read-only prompt option, is there a way to keep that for the next time someone opens it?
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ScreenUpdating = False
Dim objSheet As Worksheet
'Protecting all worksheets with password
For Each objSheet In Worksheets
If objSheet.ProtectContents = False Then objSheet.Protect "NESAFE", True, True, True, , , , , , , , , , , True, True
Next objSheet
Sheet9.Visible = False
Sheet8.Visible = False
Sheet3.Visible = False
Sheet4.Visible = False
Sheet1.Visible = False
Sheet10.Visible = False
Sheet5.Select
Range("A1").Select
Application.ScreenUpdating = True
Sheet5.Select
Range("A1").Select
ActiveWorkbook.Save
End Sub
Is there a way to only have this run if the file is in edit mode instead of read-only? Also, when it saves at the end it seems to remove my read-only prompt option, is there a way to keep that for the next time someone opens it?