How to Password Protect a Workbook with Code after it is Saved

By Admin
April 22, 2024
6 min read

How to Password Protect a Workbook with Code after it is Saved?

Securing your workbooks with passwords is a crucial step in ensuring the safety of your data. However, what if you forgot to set a password before saving your workbook? Don't worry, you can still protect it by following these steps:

  1. Open the saved workbook in Excel.
  2. Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
  3. Insert a new module by clicking Insert > Module.
  4. Copy and paste the following code:
  5. Sub ProtectWorkbook()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
    ws.Protect Password:="YourPassword"
    Next ws
    ThisWorkbook.Protect Structure:=True, Windows:=False, Password:="YourPassword"
    End Sub

  6. Replace 'YourPassword' with your desired password.
  7. Run the code by clicking Run > Run Sub/UserForm or pressing F5.
  8. Close the VBA editor and save your workbook.
  9. Your workbook is now password protected!

Remember to keep your password secure and easy to remember but hard to guess for maximum protection.

Additional Links


How To Password Protect An Excel Workbook
How To Password Protect A Excel File
How To Password Protect An Excel File
How To Password Protect Excel File
How Do I Password Protect An Excel File
How To Password Protect Excel Sheet
How To Set Password On Excel
How To Protect Excel With Password
How To Password Protect Vba Code

How To Figure Out Your Dad's Pc Password

What is the password problem?

The password problem refers to the challenges and vulnerabilities associated with creating, managing, and securing passwords, which often leads to weak or reused passwords and increased security risks.

By Admin
8 min read

Generate strong passwords tool

Online web, mobile resources for generating strong passwords...

By Admin
10 min read

Did you find this page useful?