Protect Sheet Macro

sitelbanat

Board Regular
Joined
Oct 17, 2005
Messages
152
I recorded a macro to protect 2 sheets with a password, but when I click on the macro to protect the sheet, then go to tools unprotect sheet, it does not promt me for a password. Why is that? This is the macro am useing

Sub Protect_sheet()
'
' Protect_sheet Macro
'
'

'
Sheets("LABOR INPUT").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("BUDGET SHEET").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
try this
Code:
Sheets("LABOR INPUT").Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True
change "password" to any password you like
 
Upvote 0
Hi eric, thank you very much for replying. For unprotect is it?

Code:
Sheets("LABOR INPUT").Protect Password:="password", DrawingObjects:=False, Contents:=False, Scenarios:=False

And what about Protecting the workbook, What would the code me for that?
 
Upvote 0
when you protect a sheet you can set some arguments
when unprotecting this is not the case

Sheets("LABOR INPUT").UnProtect Password:="password"
 
Upvote 0
it's impossible to protect the workbook within code
to my knowledge there is really no syntax available :(

no I'm kitting :LOL:
simply record a macro to know the syntax
Code:
    ActiveWorkbook.Protect Structure:=True, Windows:=False
    ActiveWorkbook.Unprotect
then click in the word "protect" and hit function key F1
help is right on it's way :->
syntax
expression.Protect(Password, Structure, Windows)
this gets us to something like this
Code:
Const PW As String = "1234"
    ActiveWorkbook.Unprotect Password:=PW
    ActiveWorkbook.Protect Password:=PW, Structure:=True, Windows:=False
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

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