Microsoft Office Online
Sign in to My Office Online (What's this?) | Sign in

 
 
Help and How-to
Search
Search
 
 
 
 
Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.

Help protect Word 2002 and Excel 2002 files with passwords
 
Power User Corner

By Paul Cornell

Microsoft Word 2002 helps you to protect documents by using password security. Microsoft Excel 2002 helps you protect workbooks and worksheets in the same way. Learn how to do it by using menu options or a macro.

Applies to
Microsoft Word 2002
Microsoft Excel 2002


See all Power User columns
See all columns

Your organization may store Word and Excel documents in a central location such as a network server computer. However, you may not want all of your coworkers to have unlimited access to these documents. Setting the files to a read-only status does not prevent your coworkers from opening the documents, and denying your coworkers access to the network folder outright may be too restrictive in your organization's computing environment. One solution is to help protect individual Word and Excel documents with passwords.

Help protect Word 2002 documents

In Microsoft Word 2002, you can require other users to type a password to open or modify a document, or both.

To help protect a document by using menu options

  1. With the document open and visible, on the Tools menu, click Options.
  2. Click the Security tab.
  3. Do one of the following:
    • To require a password to open the document, in the Password to open box, type a password, and then click OK. In the Reenter password to open box, type the password again, and then click OK.
    • To require a password to make changes to the document, in the Password to modify box, type a password, and then click OK. In the Reenter password to modify box, type the password again, and then click OK.
  4. To test the password, close and reopen the document.

Caution   Be sure to remember your password. Password security measures help prevent others from opening or modifying a password-protected document if they do not know its accompanying password. Here are some helpful tips on passwords:

  • Passwords should be at least eight characters in length. They should consist of a combination of letters, numbers, and symbols, and they should not consist of any words that can be found in a dictionary.
  • Passwords are case-sensitive. In other words, the password p7a4y6&y is not the same as the password P7a4y6&Y.
  • You should choose passwords that are easy for you to remember but that are not easy enough for someone else to guess them.
  • It is not recommended that you record a password, but if you must do so, store the password in a secure place.

If you do not want to require a password to open or change a document but you do want to suggest that others open it only to read and not modify it, you can select the Read-only recommended check box on the Security tab. Users will see the following message when the document is opened:

<File name> should be opened as read-only unless changes to it need to be saved. Open as read-only?

If the user clicks Yes (the default choice), the document opens but its contents cannot be changed. If the user clicks No, the document opens and its contents can be changed.

You can also password-protect a document from opening or modifying by using a macro. This is quicker than going to the Tools menu, clicking Options, clicking the Security tab, and so on.

To help protect a document by using a macro

  1. In Word, on the Tools menu, point to Macro, and then click Macros.
  2. In the Macro name box, type SetWordOpenPassword.
  3. In the Macros in list, select Normal.dot (global template).
  4. Click Create. The Microsoft Visual Basic® Editor opens.
  5. Between the code Sub SetWordOpenPassword() and End Sub type or copy the following code:

    Dim strPassword As String

    strPassword = InputBox(Prompt:="Type " & _
    "a case-sensitive password that " & _
    "must be used to open this document " & _
    "from now on, and then click OK.")

    ActiveDocument.Password = strPassword

    MsgBox Prompt:="Open password set to '" & _
    strPassword & "'."

  6. Click anywhere inside the macro code, and then, on the Run menu, click Run Sub/UserForm.
  7. Type your password, click OK, and then save and close the document. When you open it again, you will be prompted for the password.

If you want to help protect the document from being modified rather than opened, repeat the previous steps but use the SetWordWritePassword macro. Here's the code:


Dim strPassword As String

strPassword = InputBox(Prompt:="Type " & _
"a case-sensitive password that " & _
"must be used to make changes to " & _
"this document from now on, " & _
"and then click OK.")

ActiveDocument.WritePassword = strPassword

MsgBox Prompt:="Write password set to '" & _
strPassword & "'."

Help protect Excel 2002 cells, worksheets, and workbooks

In Microsoft Excel 2002, you can help protect a single cell or a group of cells on a worksheet from being modified. You can also help protect an entire worksheet, an entire workbook, or any combination of cells, worksheets, and workbooks from being modified. And finally, you can restrict cell access to specific network users.

To help protect a single cell or a group of cells on a worksheet

  1. With the worksheet open, on the Tools menu, point to Protection, and then click Allow Users to Edit Ranges.
  2. Click New.
  3. In the Title box, type a name for the single cell or group of cells.
  4. Click the Refers to cells box, and then select the single cell or group of cells on the worksheet.
  5. In the Range password box, type a password.

    Tip   You can click the Permissions button in the New Range dialog box to select users on your computer network who can have access to the single cell or group of cells.
  6. Click OK to return to the Allow Users to Edit Ranges dialog box, and then click OK again.

To help protect an entire worksheet

  1. With the worksheet open, on the Tools menu, point to Protection, and then click Protect Sheet.
  2. In the Password to unprotect sheet box, type a password.
  3. In the Allow all users of this worksheet to list, select one or more check boxes to allow users who successfully enter the password to perform additional tasks on the worksheet, such as select unlocked cells, insert rows, sort, and so on.
  4. Click OK, type your password again, and then click OK again.
  5. To test the password, close and reopen the workbook.

To help protect an entire workbook

  1. With the workbook open and visible, on the Tools menu, point to Protection, and then click Protect Workbook.
  2. In the Password (optional) box, type a password.

    Tip   To help protect the basic structure of the workbook, select the Structure check box. To help protect the behavior of the workbook's window, select the Windows check box.
  3. Click OK, type your password again, and then click OK again.
  4. To test the password, close and reopen the workbook.

Help protect an Excel 2002 workbook by using a macro

You can also password-protect a workbook from opening or modifying by using a macro. Just as in Word, this is quicker than going to the Tools menu, pointing to Protection, clicking Protect Workbook, and so on.

To help protect a workbook by using a macro

  1. In Excel, on the Tools menu, point to Macro, and then click Macros.
  2. Type SetExcelOpenPassword.
  3. In the Macros in list, select This Workbook.
  4. Click Create. The Visual Basic Editor opens.
  5. Between the code Sub SetExcelOpenPassword() and End Sub type or copy the following code:

    Dim strPassword As String

    strPassword = InputBox(Prompt:="Type " & _
    "a case-sensitive password that " & _
    "must be used to open this workbook " & _
    "from now on, and then click OK.")

    ActiveWorkbook.Password = strPassword

    MsgBox Prompt:="Open password set to '" & _
    strPassword & "'."

  6. Click anywhere inside the macro code, and then, on the Run menu, click Run Sub/UserForm.
  7. Type your password, click OK, and then save and close the document.

If you want to help protect the document workbook from being modified rather than opened, repeat the previous steps for the SetExcelWritePassword macro. Here's the code:

Dim strPassword As String

strPassword = InputBox(Prompt:="Type " & _
"a case-sensitive password that " & _
"must be used to make changes to " & _
"this workbook from now on, " & _
"and then click OK.")

ActiveWorkbook.WritePassword = strPassword

MsgBox Prompt:="Write password set to '" & _
strPassword & "'."

Keep sending that e-mail!

We look forward to receiving your e-mail messages at pwruser@microsoft.com. We really want this to be your column, so please send us your comments and favorite handcrafted Office solutions. Remember, we will not be able to feature every Office solution that we receive, we will not have the time to respond to all of your e-mail, and we are not technical support representatives. But we may feature your solution in an upcoming column.


About the author

Paul Cornell works for the Office Help team. In addition to writing the Office Power User Corner column, Paul contributes to the Office Talk column for the Microsoft Developer Network (MSDN). He is the author of the book Accessing and Analyzing Data with Microsoft Excel.

If you like this column and want to hear about more fun and useful Office offerings, sign up for our newsletter.

See all Power User columns
See all columns
advertisement