vba protect sheet with password

Roman12

Board Regular
Joined
Jun 10, 2008
Messages
117
Hi,

I have recorded the following macro to protect my different worksheets. Unfortunately, it just protects the worksheets without asking for the password. How am I able to add the password to my recorded macro?
Thank you in advance for your help.

Roman



Recorded macro:

Sub protectall()
'
' protectall Macro
' Macro recorded 01-02-2012 by RomanGraber
'

'
Sheets("Baseline overview list").Select
Cells.Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
Sheets("Options").Select
Cells.Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Range("B2").Select
Sheets("Management").Select
Cells.Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Range("A1").Select
Sheets("Overview").Select
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Like this:

Rich (BB code):
ActiveSheet.Protect Password:="YourPassword", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True

The Unprotect method also has a Password argument.
 
Upvote 0
Hi,

I tried to implement your suggestion. Is it correct that when protecting, the macro will not ask to type in the password?

If I want to unprotect all the previous worksheets again with a macro that before unprotecting asks for the password, what would the macro look like?

Thank you

Roman
 
Upvote 0
Like this?

Rich (BB code):
ActiveSheet.UnProtect Password:="YourPassword"

If the password is correct you won't be propmpted for it.
 
Upvote 0
Is there a way to protect the work sheet and still allow the use of slicers? I've unlocked the slicers in their properties, and I protected the sheet using ActiveSheet.Protect Password:="MyPassword", AllowUsingPivotTables:=True

I have multiple tabs in my workbook, this technique worked on two of the tabs and allows me to click the slicers, but on the other tabs I still cannot click the slicers. Any suggestions? I am using Excel 2013
 
Upvote 0
I am new to excel programming and macros; I made an error in my macro, I had the line:

Activesheet.Protect Password = "password" without the colon, and now it will not recognize the set password. Am I completely SOL?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top