Yes. In Excel for Microsoft 365 on Windows, you can password-protect multiple workbooks by running a VBA macro that opens each file, sets its password, and saves it. Excel does not provide a built-in command to apply an open password to a whole batch, so back up the files first and review the macro’s results before sharing them.
What “password-protect” means in Excel
People use “password-protect a file” to describe several different Excel features, and choosing the right one matters. To require a password before someone can open a workbook, use file encryption. That is the protection a batch macro in this guide applies.
Other protection options do different jobs:
- Encrypt with Password: Requires the password to open the workbook. This is the appropriate choice when the file itself should be inaccessible without the password.
- Protect Sheet: Restricts changes to worksheet cells or selected worksheet features. It does not encrypt the file or prevent someone from opening it.
- Protect Workbook: Usually protects the workbook’s structure, such as adding, deleting, or moving sheets. It is not the same as an open password.
- Read-only recommendations or permissions: These can discourage or limit some editing, but they are not a substitute for encrypting a workbook with an open password.
If your aim is to stop a recipient from viewing sensitive contents, protecting a sheet alone will not do it. Use an opening password and keep it separate from the workbook.
Use Excel’s built-in option for one workbook
For an individual file, Excel for Microsoft 365 on Windows has a built-in route: open the workbook, choose File > Info > Protect Workbook > Encrypt with Password, enter a password, confirm it, and save the file. Excel will ask for that password the next time the workbook is opened.
This is a useful first step if you want to confirm the behavior before processing a folder. Close the file and reopen it to check that Excel prompts for the password. Be sure you are selecting Encrypt with Password, not just a sheet- or structure-protection command.
On Excel for Mac, password settings are available through File > Passwords; the labels and options can differ by release. Excel for the web does not offer the same desktop workflow for adding an opening password, so use the desktop app to set it. A workbook encrypted with an opening password may also need to be opened in desktop Excel rather than Excel for the web.
Can Excel password-protect a batch without a macro?
Excel does not include a standard folder-level button that applies an opening password to every workbook at once. Its Encrypt with Password command acts on the workbook currently open. If you have only a few files, processing them one at a time may be simpler and easier to verify. If you have a large, consistent set, VBA can automate the repetitive work.
Other automation tools may be able to handle files, but the right choice depends on your organization’s security policies and the formats involved. Avoid uploading confidential workbooks to an unfamiliar online service just to set passwords. For a small batch, using Excel’s own desktop interface or a reviewed local macro is often the more transparent approach.
Batch method: run a VBA macro on a folder
The example below asks you to choose a folder and enter one password. It processes Excel workbooks directly in that folder, including .xlsx, .xlsm, .xlsb, and .xls files. It does not search subfolders. It skips the workbook containing the macro and attempts to open each other file, set its open password, and save it.
- Make a separate backup copy of the target folder. Close the target workbooks in Excel, and make sure you can write to the folder.
- Open a separate macro-enabled workbook, press Alt+F11 on Windows to open the Visual Basic Editor, and choose Insert > Module.
- Paste the code below into the module. Save the macro workbook as an .xlsm file.
- Run PasswordProtectFolder from the Visual Basic Editor or Excel’s macro list. Choose the folder and enter the password when prompted.
- Review the completion message, then test a few output files by closing and reopening them and entering the password.
Option Explicit
Sub PasswordProtectFolder()
Dim folderPath As String
Dim password As String
Dim extensions As Variant
Dim extension As Variant
Dim fileName As String
Dim fullName As String
Dim failureList As String
Dim wb As Workbook
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Choose the folder of Excel workbooks"
If .Show <> -1 Then Exit Sub
folderPath = .SelectedItems(1)
End With
password = InputBox("Enter the password to use for these files:")
If Len(password) = 0 Then Exit Sub
extensions = Array("*.xlsx", "*.xlsm", "*.xlsb", "*.xls")
Application.ScreenUpdating = False
For Each extension In extensions
fileName = Dir$(folderPath & "\" & CStr(extension))
Do While Len(fileName) > 0
fullName = folderPath & "\" & fileName
If Left$(fileName, 2) <> "~$" And _
StrComp(fullName, ThisWorkbook.FullName, vbTextCompare) <> 0 Then
Set wb = Nothing
On Error Resume Next
Set wb = Workbooks.Open(Filename:=fullName, _
UpdateLinks:=0, ReadOnly:=False, AddToMru:=False)
If Err.Number <> 0 Then
failureList = failureList & vbCrLf & fileName & _
" — could not open: " & Err.Description
Err.Clear
End If
On Error GoTo 0
If Not wb Is Nothing Then
On Error Resume Next
wb.Password = password
wb.Save
If Err.Number <> 0 Then
failureList = failureList & vbCrLf & fileName & _
" — could not save: " & Err.Description
Err.Clear
End If
wb.Close SaveChanges:=False
On Error GoTo 0
Set wb = Nothing
End If
End If
fileName = Dir$()
Loop
Next extension
Application.ScreenUpdating = True
If Len(failureList) = 0 Then
MsgBox "Finished. Check the files by reopening them."
Else
MsgBox "Finished with files needing attention:" & failureList
End If
End Sub
The code uses the same password for every successfully processed file. The InputBox displays what you type, so do not run this in a setting where someone can watch the screen. It also does not create a hidden password vault or send passwords to recipients. Share the password through a separate, appropriate channel.
As with any macro, test on copies first. A macro cannot be undone with Ctrl+Z. The code reports files it could not open or save, but a successful message is not a substitute for checking that the files reopen as expected.
What the macro does not handle automatically
The folder macro is intentionally limited: it does not recurse into subfolders, ask for a different password per workbook, or make a backup. A file may fail if it is already open, read-only, locked by another user, damaged, or protected by a password the macro does not know. Files with unusual extensions or non-Excel formats are not included.
Opening and saving a workbook can also involve prompts or application settings in some circumstances. The macro suppresses link updates by opening with UpdateLinks:=0, but it cannot decide whether external links, queries, add-ins, or organizational controls should be changed. If the folder contains important workbooks with complex connections or sensitive macros, process a small representative sample and inspect it before running a larger batch.
Excel’s modern workbook formats preserve their file type when saved normally, but legacy .xls workbooks use an older format. If you need a particular level of security or compatibility, consider converting legacy files deliberately rather than assuming that changing a password also upgrades their format.
Choose a password and manage access safely
Every workbook processed by the sample receives the same password. That is convenient for a controlled batch, but it also means that anyone who learns the password can try it on every file in that batch. For workbooks with different audiences or sensitivity levels, use separate batches and distinct passwords, or choose a managed access-control system instead.
- Use a long, unique password that is not reused for email, cloud storage, or other accounts.
- Store the password in an approved password manager or another controlled location, rather than in the same folder as the encrypted files.
- Give the password only to people who need access, and communicate it separately from the file where practical.
- Keep an unencrypted backup only if your organization’s rules allow it, and protect that backup as carefully as the originals.
- Maintain a record of which files were processed and who can retrieve the password.
Excel’s open-password encryption is different from worksheet protection, but no password system removes the need for sensible file handling. Once an authorized person opens a workbook, they may be able to copy its contents. If you need identity-based access, revocation, or activity controls, a shared location with managed permissions may be a better fit than distributing password-protected copies.
Common problems and recovery limits
If Excel does not ask for a password after the macro runs, check that the file was saved, close it completely, and reopen it in desktop Excel. The macro may have skipped it or reported a save error. Also verify that you are testing the saved file in the folder you selected, not an older copy elsewhere.
If the macro reports that a file could not be opened, check whether it is already open, marked read-only, in use by someone else, or already encrypted. A workbook that already requires a password cannot be opened by this example unless that password is supplied separately. The macro does not decrypt files or replace unknown passwords.
There is no ordinary Excel setting that reveals a forgotten opening password. Microsoft support generally cannot recover a lost password for an encrypted workbook. Keep a controlled record before encrypting important files, and test your recovery process while you still have access. Do not confuse this with sheet protection, which is a different feature and has different security properties.
When permissions or another approach are better
Password encryption is useful when you need to send a file that should require a shared secret to open, or when a workbook must remain protected outside a managed storage environment. It can be less convenient when many people need different permissions, when access must be revoked quickly, or when a team needs a reliable audit trail.
For collaboration, consider storing the workbook in OneDrive or SharePoint and granting access to named people or groups, subject to your organization’s settings. Access controls can be easier to manage than a shared password, though they depend on the account and service policies. For a file that must simply be read-only, use appropriate sharing permissions rather than assuming sheet protection prevents copying or viewing. Match the method to the risk: encryption protects access to the file, while permissions govern who can access a shared copy.
Frequently Asked Questions
Can I password-protect multiple Excel files at once without VBA?
Not with a built-in batch command in Excel for Microsoft 365 on Windows. You can protect each workbook individually through File > Info > Protect Workbook > Encrypt with Password, or automate a batch with a carefully tested macro.
Does Protect Sheet stop someone from opening my Excel file?
No. Protect Sheet restricts certain edits after the workbook is open; it does not require a password to open or encrypt the workbook. Use Encrypt with Password when the contents should be inaccessible without an opening password.
Can I use a different password for every workbook?
Yes, but the sample macro applies one password to the whole batch. To use distinct passwords, process files individually or adapt the automation to request and securely manage each password. Avoid putting a password list in the workbook or in an unprotected text file.
Will the macro include files in subfolders?
No. It processes only the selected folder’s top level and the four extensions listed in the code. Run it separately on subfolders, or have a developer adapt and test it if recursive processing is required.
What if I forget the password?
Excel does not provide a normal recovery option for a forgotten opening password, and Microsoft generally cannot retrieve it. Keep the password in an approved secure location and verify access before relying on the encrypted workbook as your only copy.
Related
- OpenOffice Excel Files: How to Open, Edit, and Save
- Open Excel Files Online: Your Options Explained
- Open an Excel Sheet: Quick Steps and File Options
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Excel Shortcut to Collapse a GroupIn Excel for Microsoft 365 on Windows, select a cell in the grouped detail rows or columns, then…
- Google Sheets COUNTIF: Count Non-Empty Cells in a RangeIf your entries are in A2:A100, count cells that are not empty in Google Sheets with =COUNTIF(A2:A100,"<>"). The…
- How to Present PowerPoint and See Your Speaker NotesTo present PowerPoint while keeping your notes visible, connect your computer to a second screen, set the displays…
- Find Excel Workbook Links in Microsoft ExcelTo find links to other Excel workbooks in Microsoft 365 for Windows, open Data > Workbook Links if…
- Excel Payment Plan: Build an Installment ScheduleTo make an Excel payment plan, enter the amount borrowed, annual interest rate, and number of monthly payments,…
- How to Add a Running Header in Microsoft Word 2019To add a running header in Word 2019, choose Insert > Header, select a layout or Edit Header,…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.