Can I create a Macro to protect & unprotect my worksheet

Amanda80

New Member
Joined
Sep 15, 2006
Messages
19
Each time I attempt this, it stops my macro in it's tracks because my workbook is protected once I go through the motions of recording the macro.

Please help!

Thanks :biggrin:
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Welcome to the Board!

You can use:

Code:
ActiveSheet.Unprotect "PasswordHere"

Or substitute ActiveSheet with Sheets("SheetName").

But you can record a macro protecting and unprotecting sheets, you just can't capture the password.

Hope that helps,

Smitty
 

Amanda80

New Member
Joined
Sep 15, 2006
Messages
19
It worked!

Thank you very much! You have no idea how much time this has saved me....

I used the same code, but with "Protect" instead to protect all my sheets again.

Thanks again!

Amanda
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
To Protect/Unprotect all of them at once you can use:

Code:
Sub ProtectAll()
  Dim ws as Worksheet
     For each ws in ActiveWorkbook.Worksheets
        ws.Protect
     Next ws
End Sub

And vice versa to Unprotect.

Smitty
 

Watch MrExcel Video

Forum statistics

Threads
1,109,360
Messages
5,528,233
Members
409,809
Latest member
VICKRAM

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top