Search TeachExcel.com
TeachExcel.com
TE
Teach Excel MS Office Tutorials Excel Consulting Services Excel Forum
Excel Video Tutorials Excel Tips Free Excel Macros Excel Help Resources Contact TeachExcel
Video Tutorials
  • Free Macros
  • Excel Help Directory
  • Excel 2007 Resources
  • Keyboard Shortcuts
  • Excel Forum
  • Contact/About

Macros
Excel Tutorials For Macros

Protect and Unprotect All Worksheets at Once


Bookmark and Share

This will allow you to protect or unprotct all worksheets in a workbook at once. It doesn't allow you to input a password; however, if you run the unprotect_all macro and there are worksheets that are password protected, it will prompt you to input the password in order to unprotect the worksheet and will do so for every worksheet that is password protected.
Where to install the macro:  Module

Protect All Worksheets at Once

Sub Protect_All()

For i = 1 To Sheets.Count
Sheets(i).Protect
Next i

End Sub

Unprotect All Worksheets at Once

Sub Unprotect_All() For i = 1 To Sheets.Count Sheets(i).Unprotect Next i End Sub

Bookmark and Share


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

      For Excel Versions Prior to Excel 2007
      Go to Tools > Macros > Visual Basic Editor

      For Excel 2007
      Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

    1. Go to the menu at the top of the window and click Insert > Module
    2. Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
    3. Go to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Go to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
    5. Go to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.



Similar Helpful Excel Resources

Unprotect/protect Worksheets In Vba - Excel

View Content
I'm trying to run macros on protected worksheets and I have the following code:

VB:

 
Public UniversalPassword As String 
Sub AccelCurrentYours() 
     
    UniversalPassword = "Tampa" 
     
    ActiveSheet.Unprotect Password:=UniversalPassword 
    Sheets("Support Calculations").Unprotect Password:=UniversalPassword 
     
     '[code to be run]
     
    ActiveSheet.Protect Password:=UniversalPassword 
    Sheets("Support Calculations").Protect Password:=UniversalPassword 
End Sub 


If you like these VB formatting tags please consider sponsoring me in support of injured Royal Marines



The problem with the code is that VBA will not acknowledge the "unprotect" commands above. I've double-checked to make sure the passwords were correct to begin with but when the code runs the "unprotect" commands, I get an error within the excel spreadsheet saying that I'm trying to run an operation on a protected worksheet that needs to be unprotected. I'm not sure what I'm missing above and what's really odd is that similar code was working before. I'm not sure if I accidentally changed a property or something of that nature.

Thanks!

Protect/unprotect All Worksheets - Excel

View Content
Is there a way to easily unprotect all the worksheets in a workbook? For
example, I have a workbook with 20 worksheets (one for each employee). The
worksheets have been individually protected (except for the select cells into
which I enter data. Now with the new year, I would like to unprotect all the
worksheets so I can change the (previously protected) field that contains
the year and then reprotect all the worksheets. Thanks.


Protect / Unprotect All Worksheets At Once - Excel

View Content
Hello, I am using the VBA code below in my spreadsheet to automatically protect/unprotect all of my worksheets at once. The code works great, but I was hoping to tweak it slightly so that when I'm prompted to type in the password, it will show the password as **** as I type it (as opposed to displaying the actual password). Does anyone know of a way to do this? (I apologize that I don't know how to insert the VBA code so that it is in the special gray box that I have seen on other posts - this website was the origin of the code, which might be easier to view: http://www.vbaexpress.com/kb/getarticle.php?kb_id=142 ) . . .


Option Explicit

Sub ProtectAll()

Dim wSheet As Worksheet
Dim Pwd As String

Pwd = InputBox("Enter your password to protect all worksheets", "Password Input")
For Each wSheet In Worksheets
wSheet.Protect Password:=Pwd
Next wSheet

End Sub

Sub UnProtectAll()

Dim wSheet As Worksheet
Dim Pwd As String

Pwd = InputBox("Enter your password to unprotect all worksheets", "Password Input")
On Error Resume Next
For Each wSheet In Worksheets
wSheet.Unprotect Password:=Pwd
Next wSheet
If Err 0 Then
MsgBox "You have entered an incorect password. All worksheets could not " & _
"be unprotected.", vbCritical, "Incorect Password"
End If
On Error Goto 0

End Sub

Protect / Unprotect All Worksheets - Excel

View Content
Currently, I'm using the following code on an Active X command button to unprotect all worksheets within my workbook ...

Code:

Sub UnProtectSheets()
  Dim ws As Worksheet
  For Each ws In ThisWorkbook.Sheets
       ws.Unprotect Password:="ana"
  Next ws
End Sub


however, it doesn't seem to be working.

Have I missed something obvious ?

Chris

Using Macro To Protect And Unprotect Worksheets - Excel

View Content
I installed these macros on a sample workbook and they function properly. When I run the protect macro all the pages are protected properly and visa versa. So how does the password function work?

Code located at: http://www.excelforum.com/excel-prog...ml#post2285150

Protect/unprotect All Worksheets In Workbook ? - Excel

View Content

-- Is it possible to protect/unprotect all worksheets in a workbook at once
instead of having to do each individually if the password is the same?

News Gal


Protect/unprotect Multiple Worksheets - Excel

View Content
I used the following macro from an earlier posting to protect multiple
worksheets in a workbook and it worked great. (Thank you Kevin Backmann!!!)

Now I would like a macro to do the reverse - that is unprotect all
worksheets. I tried the same macro changing every instance of the word
Protect to Unprotect, but that didn't work. What can I do to make this work?

Thanks. (I've copied and pasted Kevin's earlier posting below

-------------------------------------------

"The following macro cycless through all the worksheets in the active
workbook, protecting them and assigning the password of "Password"

Sub ProtectAll()

Dim wb As Workbook
Dim ws As Worksheet

Set wb = ActiveWorkbook

For Each ws In wb.Worksheets
ws.Protect DrawingObjects:=True, _
Contents:=True, Scenarios:=True, _
Password:="Password"
Next ws

Set wb = Nothing
Set ws = Nothing

End Sub

Place it in a VBA module by pressing Alt+F11, click INSERT on the menu and
select MODULE. You can either type the code above or cut and paste it. To
run the macro select TOOLS on the menu, click MACRO and then select MACROS.
The macro will be in the list of available macros. You can select it and
then click the RUN command button."



Protect/unprotect Grouped Worksheets - Excel

View Content
Hi, I have these macro's below that protect/unprotect all worksheets in the
book. How do I get them to only work on the sheets I selected?

TIA

Todd


Sub ProtectAll()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Protect Password:=""
Next ws
End Sub

Sub UnprotectAll()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Unprotect Password:=""
Next ws
End Sub


Using Macro To Protect And Unprotect Worksheets - Excel

View Content
I am looking for a way to protect and unprotect all worksheets with a password through a macro. I have excel 2007.
Thanks

Trouble With Unprotect & Protect Worksheets In My Code - Excel

View Content
I have all my codes working and protected the cells in the 2 worksheets, now it is telling me that there is a run time eror '1004' for the PasteSpecial method of Range class failed.

I have put in the codes to unprotect/protect the sheet back and if i leave them unprotected it works fine. I am using a command button to copy the data from one sheet to the second sheet and it fails when it gets to the second sheet. The debug highlites the one below that is in Italics. Cannot find out how to make it work.

Code:

Private Sub CommandButton11_Click()
With Worksheets("Activity Entries")
.Range("A3:AB3").Copy
End With
With Worksheets("Email to Scheduler_s").Unprotect
 Worksheets("Email to Scheduler_s").Range("B2").PasteSpecial Paste:=xlPasteValues
 Worksheets("Email to Scheduler_s").Range("B2").PasteSpecial Paste:=xlPasteFormats
With Worksheets("Email to Scheduler_s").Protect
End
End
End With 'sheet2
End 'sheet1
End With
End Sub




Random Tutorials
Extract Text from Cells - Intermediate Example
(Intermediate)
Introduction to Making Formulas in Excel
(Easy)
Function and Formulas Lookup in Excel
(Easy)
AND(), OR(), and IF() Statements/Formulas
(Intermediate)
How to record a Macro - And what One is
(Easy)
How to 'Protect' a Worksheet and Workbook
(Easy)
Submit Inquiry Here
  • Prices From $10
Name:*
E-mail:*
Request:*
The macro(s) on this page will be sent with the request.
Contact | Privacy Policy | Disclaimer
Copyright© 2012 TeachExcel.com