
- MS Excel Basics
- Excel - Home
- Excel - Getting Started
- Excel - Explore Window
- Excel - Backstage
- Excel - Entering Values
- Excel - Move Around
- Excel - Save Workbook
- Excel - Create Worksheet
- Excel - Copy Worksheet
- Excel - Hiding Worksheet
- Excel - Delete Worksheet
- Excel - Close Workbook
- Excel - Open Workbook
- Excel - Context Help
- Editing Worksheet
- Excel - Insert Data
- Excel - Select Data
- Excel - Delete Data
- Excel - Move Data
- Excel - Rows & Columns
- Excel - Copy & Paste
- Excel - Find & Replace
- Excel - Spell Check
- Excel - Zoom In-Out
- Excel - Special Symbols
- Excel - Insert Comments
- Excel - Add Text Box
- Excel - Undo Changes
- Formatting Cells
- Excel - Setting Cell Type
- Excel - Setting Fonts
- Excel - Text Decoration
- Excel - Rotate Cells
- Excel - Setting Colors
- Excel - Text Alignments
- Excel - Merge & Wrap
- Excel - Borders and Shades
- Excel - Apply Formatting
- Formatting Worksheets
- Excel - Sheet Options
- Excel - Adjust Margins
- Excel - Page Orientation
- Excel - Header and Footer
- Excel - Insert Page Breaks
- Excel - Set Background
- Excel - Freeze Panes
- Excel - Conditional Format
- Working with Formula
- Excel - Creating Formulas
- Excel - Copying Formulas
- Excel - Formula Reference
- Excel - Using Functions
- Excel - Builtin Functions
- Advanced Operations
- Excel - Data Filtering
- Excel - Data Sorting
- Excel - Using Ranges
- Excel - Data Validation
- Excel - Using Styles
- Excel - Using Themes
- Excel - Using Templates
- Excel - Using Macros
- Excel - Adding Graphics
- Excel - Cross Referencing
- Excel - Printing Worksheets
- Excel - Email Workbooks
- Excel- Translate Worksheet
- Excel - Workbook Security
- Excel - Data Tables
- Excel - Pivot Tables
- Excel - Simple Charts
- Excel - Pivot Charts
- Excel - Keyboard Shortcuts
- MS Excel Resources
- Excel - Quick Guide
- Excel - Useful Resources
- Excel - Discussion
How to Automatically Protect All Worksheets When Closing an Excel Workbook?
In general, protection is used in Excel to prevent users from editing it. However, we will always forget to protect the sheet, but we can automate it by using the VBA application. This tutorial will help you understand how we can automatically protect all worksheets when closing the Excel workbook. Protecting the sheet is nothing; the sheet will be in read-only mode, and we will not be able to edit the contents of the sheet. In this tutorial, we will be saving the whole workbook using the save workbook command.
Automatically Protect All Worksheets When Closing an Excel Workbook
Here we will insert a VBA code for the whole workbook along with a password. Let us see a simple process to know how we can automatically protect all worksheets when closing the Excel workbook. We will be using the VBA application to complete our process.
Step 1
Let us consider an Excel workbook that contains multiple worksheets, and right-click on the sheet name and select View Code to open the vba application. Then double-click on this workbook and copy the below-mentioned programme into the textbox as shown in the below image.
Example
Private Sub Workbook_BeforeClose(Cancel As Boolean) 'Update by Nirmal Dim xSheet As Worksheet Dim xPsw As String xPsw = "1234" For Each xSheet In Worksheets xSheet.Protect xPsw Next End Sub
In the above code, 1234 is the password to unlock the workbook.

Step 2
Now save the sheet as a macro-enabled template, close the VBA application using the command "Alt + Q", and then close the workbook. When we try to edit the worksheet from now on, an error message will appear, as shown in the image below.

We can unlock the sheet by clicking on "unprotect" and entering the password 1234.
Conclusion
In this tutorial, we used a simple example to demonstrate how we can automatically protect all worksheets when closing an Excel workbook.
- Related Articles
- How to Automatically Hide Specific Worksheets When Opening an Excel File?
- How to clear filters when opening, saving or closing workbook in Excel?
- How to automatically close all collapsible elements inside of the accordion when closing the accordion?
- How to Start at Cell A1 Always when Opening an Excel Workbook?
- How to Automatically Open Files When Starting Excel?
- How to add header or footer to all worksheets/pages in Excel?
- How to Always Start the Same Worksheet When Opening a Workbook in Excel?
- How to encrypt the MS excel workbook?
- How to Apply a Template to an Existing Chart/Workbook in Excel?
- How to Automatically Reapply Auto-Filter When the Data Changes in Excel?
- How to AutoSum Multiple Rows/Columns/Worksheets in Excel?
- How to Automatically Change All Pictures to Move and Size with Cells in Excel?
- How to Always Search the Whole Workbook in Excel?
- How to get the current workbook name in Excel?
- How to Add New Worksheets with Customized Names in Excel?
