How do I auto-protect a worksheet?

G

Guest

I have set my w/sheet to "protect" with some cell left "un-protected" for
easy data entry. I want to share my w/sheet and increase it's security level.
Is there a way to set the w/sheet on a "auto-protect" mode so that the file
is "protected" every time I close the file?. Using the manual "protect sheet"
is not so efficient as we tend to forget to "re-protect" it again when we
"unprotect" the w/sheet for maintainance purposes.
 
G

Guest

You could get excel to automatically protect sheets when the workbook is
closed. To do this you would use the workbook beforeclose event. Right Click
the Excel icon just to the left of the file menu. Select View Code to display
the Workbook code sheet. Paste this code into the sheet.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim sht As Worksheet
For Each sht In Worksheets
sht.Protect
Next sht
End Sub

This will protect every worksheet in your workbook. If you want to protect
just one sheet say "Sheet1" then the code should read:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Sheet1").Protect
End Sub

Hope this helps
Rowan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top