Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Forcing a Worksheet to be Protected Again.

Forcing a Worksheet to be Protected Again

by Allen Wyatt
(last updated February 17, 2016)

Barry can lock a worksheet so that only those to whom he gives the password can edit it. If the person enters the password, makes edits, and then saves the workbook containing the worksheet, that worksheet is then unprotected. Barry wonders if there is a way that, when saving the worksheet, Excel can remind the user to once again protect the worksheet using the same password originally used.

There are several ways you can go about solving this problem. If you've assigned a password to a worksheet, then you simply need to make sure that the same password is used to reprotect the worksheet when the workbook is saved. This is easily done by using a macro that can be tied to the BeforeSave event. This macro should be added to the ThisWorkbook object:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Sheets("ABC").Protect ("XYZ")
End Sub

This example assumes that the worksheet you want to protect is named ABC and that the password used to protect the worksheet is XYZ. You'll want to change these values to reflect your actual worksheet and password.

Note that this macro automatically reprotects the worksheet whenever the workbook is saved. Thus, if a user has a long working session with the worksheet and saves the workbook many times during that session, then they will need to unprotect the worksheet quite often. If you prefer, you can create a macro that will ask if the worksheet should be reprotected:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If MsgBox("Reprotect Sheet ABC?", vbYesNoCancel) = vbYes Then
        Sheets("ABC").Protect ("XYZ")
    End If
End Sub

Of course, this approach means that it is possible that a worksheet would not be protected again, if the user chose to not reprotect it.

Another approach doesn't involve using macros at all, but uses a different way to do your protection. In traditional worksheet protection, you format individual cells as unlocked, then you apply protection to the worksheet so that any locked cells cannot be changed. If you don't mark any cells as unlocked (which seems to be what Barry is doing), then nothing in the worksheet can be changed without the password.

Starting with Excel 2002 you can actually protect individual ranges of cells within a worksheet. Follow these steps:

  1. Choose Protection from the Tools menu and then choose Allow Users to Edit Ranges. Excel displays the Allow Users to Edit Ranges dialog box. (See Figure 1.)
  2. Figure 1. The Allow Users to Edit Ranges dialog box.

  3. Click the New button. Excel displays the New Range dialog box. (See Figure 2.)
  4. Figure 2. The New Range dialog box.

  5. In the Title box, enter the name you want to use for this range.
  6. In the Refers to Cells box, enter the range you want users to be able to edit. (If there are multiple ranges you want to use this same password, you can separate those ranges with a comma.)
  7. In the Range Password box, enter the password you want to give to your users.
  8. Click on OK. You are again asked to enter the password.
  9. Enter the password you used in step 5 a second time. The range now appears in the Allow Users to Edit Ranges dialog box.
  10. Click OK to close the Allow Users to Edit Ranges dialog box.
  11. Protect your worksheet as you normally would.

There is only one thing you need to remember when you protect your worksheet (step 9). Since you've not unlocked any cells, then all cells in the worksheet will be protected. You need to make sure that the protection you apply allows locked cells to be selected. If, after the worksheet is protected, a user tries to edit a cell that is in the range you specified in step 4, they are asked for the password you specified in step 5. When they provide it, they can make edits to any cells in the range.

The cool thing about this approach is that worksheet protection is not removed—the worksheet is still protected because the user never removed that protection. Thus, the user never needs to know the password for the entire worksheet. When the user closes and reopens the workbook, the worksheet is still protected, just as you need. Plus, you don't have the unavoidable downside of macros—that they can be disabled by a user when they open the workbook.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11972) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Forcing a Worksheet to be Protected Again.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Limitations On Finding Characters

When you search for information in a worksheet, you expect Excel to return results that make sense. If you don't get a search ...

Discover More

Saving Personalized Copies of a Document

Need a series of documents that include an individual's name or a company name? Here's a handy little macro that will make ...

Discover More

Simple Relative References in External Links

Linked data can be essential in pulling information from one workbook to another. One downside of links, however, is that ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

MORE EXCELTIPS (MENU)

Detecting Types of Sheets in VBA

When processing workbook information in a macro, you may need to step through each worksheet to make some sort of changes. It ...

Discover More

Viewing Same Cells on Different Worksheets

When switching from one worksheet to another, you might want to view the same portion of the new worksheet that you were ...

Discover More

Quickly Inserting a New Worksheet

Want a quick way to insert a worksheet? There's nothing faster than using the handy shortcut.

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments for this tip:

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)

This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.

Links and Sharing
Share