We need to unprotect workbook at the beginning of the procedure to do any changes to the workbook. If you forgot the password, you cannot unprotect the workbook.
Why we need to Unprotect a Workbook using VBA?
Unprotect method of workbook object has no effect if the workbook is not protected. It removes protection from a workbook.
VBA Unprotect Workbook – Syntax
Here is the syntax to Unprotect workbook using VBA.
Workbooks(“Your Workbook Name”).Unprotect(
Where
Password: Its Optional argument. It specifies a case sensitive password for the workbook. When you want to unprotect your protected workbook you must specify your password.
Structure: Its Optional parameter. The default value is False. If we mention it as True that means protect the workbook structure.
Windows: Its Optional parameter. The default value is False. If we mention it as True that means protect the workbook windows.
In the above syntax we are using ‘Unprotect’ method of workbook object to unprotect the workbook.
VBA Unprotect Workbook: Example 1
Please find the below example, It will show you how to Unprotect the workbook.
Sub Unprotect_Sheet()
ActiveWorkbook.Unprotect “YourPassword”, True, True
End Sub
In the above example we are unprotecting the workbook by using ‘Unprotect’ method of Workbook object in the active workbook. When working with workbook code has password Unprotected, if you want to do any changes in the code first you have to Unprotect the password at the beginning of the procedure and
VBA Unprotect Workbook – Instructions
Please follow the below step by step instructions to execute the above mentioned VBA macros or codes:
- Open an Excel Workbook
- Press Alt+F11 to Open VBA Editor
- Insert a Module from Insert Menu
- Copy the above code for activating a range and Paste in the code window(VBA Editor)
- Save the file as macro enabled workbook
- Press ‘F5’ to run it or Keep Pressing ‘F8’ to debug the code line by line.
A Powerful & Multi-purpose Templates for project management. Now seamlessly manage your projects, tasks, meetings, presentations, teams, customers, stakeholders and time. This page describes all the amazing new features and options that come with our premium templates.
LIMITED TIME OFFER
Advanced Project Planning Templates
Excel Templates
120+ Project Management Templates Pack
Excel | PowerPoint | Word
ULTIMATE RESOURCE MANAGEMENT TEMPLATE
Excel Template
50+ Essential Project Management Templates
Excel | PowerPoint | Word
Project Portfolio Management Templates
Excel | PowerPoint Templates
50+ Excel Project Management Templates
Excel Templates