5 Quick Ways to Password Protect a Microsoft Excel File

Do you want to password protect your Excel file?

Often you store sensitive personal, business, or academic research data in Microsoft Excel. You don’t want that workbook to fall into the wrong hands who’ve got malicious intentions. Here comes the Excel password protection feature.

In this quick Excel tutorial, I’ll show how to password-protect an Excel file in step-by-step. There are various methods to create a password-protected Excel file.

I’ll present here five quick methods involving the Excel app interface features and scripting. You can choose the method that meets your requirements and Excel expertise.

What Is Password Protection in Excel?

What Is Password Protection in Excel
A password-protected Excel file

Excel password protection refers to the security feature that allows you to prevent the unintended audience from accessing your Excel files. When you get your datasets password protected in Excel, it requires a password for opening or modifying the dataset or the entire Excel file.

Password protection in Excel works on various levels as mentioned below:

  • Prevent shared PC users from opening the Excel file if they don’t know the password. It’s just like accessing Windows user accounts or Outlook email accounts.
  • Allow anyone to open the Excel file to refer to the data restrict data modification with a password.

By utilizing password protection, you can control who has access to your data, preventing unauthorized users from viewing or altering the information. However, it’s essential to choose strong passwords and to keep them secure, as a weak or compromised password could undermine the effectiveness of this security measure.

Password protection in Excel isn’t a foolproof way to protect your datasets, data analytics, and data visualization objects on the spreadsheet file. Here are the things you must remember before using password protection in Excel:

  • Microsoft Excel doesn’t allow you to recover passwords you set in your Excel files. If you forget the password, you can’t open the workbook anymore.
  • There are Excel VBA-based scripts that allow hackers to hack an Excel file protected with a password.
  • Excel workbook and worksheet passwords are case-sensitive.

Reasons to Use Excel Password Protection

Here are the upsides of using the Excel password protection feature:

  • Often, your employees or contractors might mistakenly email Excel files to people outside the organization. Here, you want to prevent unauthorized people from accessing sensitive Excel workbooks by enabling password protection.
  • At home or school, you use shared PCs and want to prevent other users from accessing the content of your Excel dataset or visualizations.
  • Setting up Excel file passwords and sharing those with authorized users creates a sense of accountability. If there are any unscrupulous modifications in your Excel file, you know that users with the passwords are the responsible persons.
  • You can meet regulatory or organizational requirements for data protection by implementing password security measures on sensitive Excel files.
  • Safeguard customer and user information or proprietary data by adding password protection to Excel files that contain such sensitive details.
  • Moreover, you can use password protection as part of version control measures to restrict modifications to specific versions of Excel files.

Now, find below the common four methods to password-protect Excel files:

Password Protect Excel Using Protect Workbook

The Protect Workbook user interface button is the primary option to encrypt your Excel file with a password. Find below the steps you can follow:

Click File
Click File
  1. Launch Microsoft Excel and open the file you want to protect.
  2. Click on the File tab in the top-left corner of the Excel window.
Encrypt with password
Encrypt with password
  1. In the File menu, select Info from the left menu.
  2. In the Info menu, click on the Protect Workbook dropdown.
  3. A small window will appear. Choose Encrypt with Password.
Encrypt document
Encrypt document
  1. Enter the password you want to use to protect the file. Make sure to use a strong and secure password that you can easily remember.
  2. You’ll be asked to confirm your password by entering it again.
Protect workbook message
Protect workbook message
  1. The Protect Workbook button shall now show this message: “A password is required to open this workbook.”
  2. This message indicates you’ve successfully set up a password for the Excel workbook.
Save excel workbook
Save excel workbook
  1. After setting up the password, save the file. This step is crucial; otherwise, the password protection won’t take effect.
Enter password
Enter password
  1. The next time you or someone else opens the Excel file, there will be a password prompt.

Write down the password in a safe online or offline note to refer to it when you forget the code. You can also write down a password hint if you don’t want to write down the exact password for security reasons.

Password Protect Excel Using Save As

When you save an Excel workbook on the Save As dialog, there’s an option to convert the workbook to a password-protected Excel file. Here’s how to password-protect an Excel file from the Save As dialog:

The browse option
The browse option
  1. Open the Microsoft Excel workbook that you want to protect using a password.
  2. Click on the File tab in the top-left corner of the Excel window.
  3. In the File menu, select Save As.
  4. Click the Browse option below the Save As section on the right.
Tools on Save As
Tools on Save As
  1. The Save As dialog will pop up.
  2. Click on the Tools dropdown menu and select General Options.
How to Password Protect an Excel File using Tools
How to Password Protect an Excel File using Tools
  1. On the General Options dialog, you need to enter two passwords as mentioned below:
    • Password to open.
    • Password to modify.
  2. Once done entering the passwords, click the OK button.
Saving an excel file
Saving an Excel file
  1. Click Save so that the Excel file’s password protection can take effect.

Password Protect Excel Using Protect Sheet

Often you may want the recipient to be able to open an Excel file but don’t want them to modify it. If you follow the methods mentioned so far, you can’t create an Excel workbook that opens in read-only mode protected by a password.

Follow these steps to create a read-only Excel workbook protected using a password:

Protect worksheet
Protect worksheet
  1. Open your Excel workbook.
  2. Go to a worksheet that you want to lock using a password.
  3. Click on the Review tab and choose the Protect Sheet option on the Protect commands block.
  4. The Protect Sheet dialog shall open.
  5. Enter a password in the relevant field of the dialog box.
  6. Click OK.
Confirm password
Confirm password
  1. Enter the same password on the Confirm Password dialog and click OK to save it.
  2. Repeat the steps for all the worksheets to protect those with passwords.

Password Protect Excel Using Office Scripts

If you’ve got Microsoft 365 Business Standard or a better subscription, you can use Office Scripts to automate the Excel password protection task. Here’s how:

Creating and running OS code
Creating and running OS code
  1. Open your Excel workbook and go to the worksheet you want to protect with a password.
  2. Click on the Automate tab and then select the New Script button inside the Scripting Tools commands block.
  3. The Code Editor shall show up on the right side of the Excel app.
  4. Copy and paste the following script into the Code Editor:
function main(workbook: ExcelScript.Workbook, password: string) {
    let selectedSheet = workbook.getActiveWorksheet();
    selectedSheet.getProtection().protect({
        // Specify permissions here (e.g., allowFormatCells: false)
        allowFormatCells: false,
        allowFormatColumns: false,
        allowFormatRows: false,
        // ... other options
    }, password);
}
  1. Click the Save script button.
  2. Click the Run button to execute the script.
Setting a password
Setting a password
  1. Enter a password of your choice in the dialog box that pops up.
  2. To protect another worksheet, run the script from that worksheet.

This Office Scripts code lets you password-protect the worksheet only. So, when you need to create a password-protected and read-only Excel file, you can use this script.

Password Protect Excel Using VBA

Another great way to automate the password protection feature of an Excel workbook file is Excel VBA.

Here’s the script and steps to utilize it in a VBA macro:

Create a VBA script
Create a VBA script
  1. Press the Alt + F11 keys together to launch the Excel VBA Editor.
  2. Click on the Insert tab of the Excel VBA toolbar.
  3. On the context menu that opens, select Module.
  4. Copy and paste this script into the new module:
Sub EncryptWorkbookWithPassword()
    ' Set your desired password
    Dim password As String
    password = "YourPasswordHere"
    
    ' Encrypt the workbook with the specified password
    ActiveWorkbook.Password = password
End Sub
  1. Replace “YourPasswordHere” with the password string of your choice.
  2. Click the Save button.
Save as
Save as
  1. On the Microsoft Excel dialog, click on the Go back button.
  2. Select the Excel Macro-Enabled Workbook (XLSM) file type in the Save as type drop-down.
  3. Click the Save button on the Save As dialog.
  4. Close the Excel VBA Editor.

To execute the macro, follow these steps:

Running a macro
Running a macro
  1. Press Alt + F8 to open the Macro dialog box.
  2. Select the EncryptWorkbookWithPassword macro.
  3. Click on the Run button.

Microsoft Excel will ask you to rewrite the Excel file. Click Save on that prompt.

The next time you close and open that specific Excel workbook, you must enter the password you entered in the above macro.

Related readings:

6 Ways to Mark a Workbook as Final in Microsoft Excel
5 Ways to Lock and Unlock Formulas in Microsoft Excel
How To Make a Sheet Read-Only in Microsoft Excel

Conclusion

So, these are all the methods you can follow to password-protect an Excel file.

If you’re a new to intermediate-level Excel user, try the methods that involve Protect Workbook, Save As, and Protect Sheet functionalities.

If you’ve been using Excel for a while and know how to use Excel Automate via Office Scripts or Excel VBA Editor, you should try the relevant methods above.

Were you able to protect your Excel workbook with a password by following the above methods? Do you know a better method that I failed to mention above? Do let us know by commenting below.

About the Author

Tamal Das

Tamal Das

I'm a freelance writer at HowToExcel.org. After completing my MS in Science, I joined reputed IT consultancy companies to acquire hands-on knowledge of data analysis and data visualization techniques as a business analyst. Now, I'm a professional freelance content writer for everything Excel and its advanced support tools, like Power Pivot, Power Query, Office Scripts, and Excel VBA. I published many tutorials and how-to articles on Excel for sites like MakeUseOf, AddictiveTips, OnSheets, Technipages, and AppleToolBox. In weekends, I perform in-depth web search to learn the latest tricks and tips of Excel so I can write on these in the weekdays!

Subscribe

Subscribe for awesome Microsoft Excel videos 😃

Related Posts

Comments

2 Comments

  1. sw

    how do you protect sheets for user wise access on sharepoint. I want users to see only the sheet they have access to on a sharepoint.

    Reply
    • John MacDougall

      I would figure out another way to securely share info. There are lots of tools in the Microsoft 365 suite that are probably more suitable depending on your specifics.

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get the Latest Microsoft Excel Tips

Follow Us

Follow us to stay up to date with the latest in Microsoft Excel!

Subscribe for awesome Microsoft Excel videos 😃