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?
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:
- Launch Microsoft Excel and open the file you want to protect.
- Click on the File tab in the top-left corner of the Excel window.
- In the File menu, select Info from the left menu.
- In the Info menu, click on the Protect Workbook dropdown.
- A small window will appear. Choose Encrypt with Password.
- 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.
- You’ll be asked to confirm your password by entering it again.
- The Protect Workbook button shall now show this message: “A password is required to open this workbook.”
- This message indicates you’ve successfully set up a password for the Excel workbook.
- After setting up the password, save the file. This step is crucial; otherwise, the password protection won’t take effect.
- 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:
- Open the Microsoft Excel workbook that you want to protect using a password.
- Click on the File tab in the top-left corner of the Excel window.
- In the File menu, select Save As.
- Click the Browse option below the Save As section on the right.
- The Save As dialog will pop up.
- Click on the Tools dropdown menu and select General Options.
- On the General Options dialog, you need to enter two passwords as mentioned below:
- Password to open.
- Password to modify.
- Once done entering the passwords, click the OK button.
- 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:
- Open your Excel workbook.
- Go to a worksheet that you want to lock using a password.
- Click on the Review tab and choose the Protect Sheet option on the Protect commands block.
- The Protect Sheet dialog shall open.
- Enter a password in the relevant field of the dialog box.
- Click OK.
- Enter the same password on the Confirm Password dialog and click OK to save it.
- 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:
- Open your Excel workbook and go to the worksheet you want to protect with a password.
- Click on the Automate tab and then select the New Script button inside the Scripting Tools commands block.
- The Code Editor shall show up on the right side of the Excel app.
- 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);
}
- Click the Save script button.
- Click the Run button to execute the script.
- Enter a password of your choice in the dialog box that pops up.
- 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:
- Press the Alt + F11 keys together to launch the Excel VBA Editor.
- Click on the Insert tab of the Excel VBA toolbar.
- On the context menu that opens, select Module.
- 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
- Replace “YourPasswordHere” with the password string of your choice.
- Click the Save button.
- On the Microsoft Excel dialog, click on the Go back button.
- Select the Excel Macro-Enabled Workbook (XLSM) file type in the Save as type drop-down.
- Click the Save button on the Save As dialog.
- Close the Excel VBA Editor.
To execute the macro, follow these steps:
- Press Alt + F8 to open the Macro dialog box.
- Select the EncryptWorkbookWithPassword macro.
- 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.
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.
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.