Unprotect question.

V

VB Newbie

In response to a recent posting, JulieD helped out someone with a script to
unprotect and the protect a worksheet. It works great for me, except for one
thing. When I go up to unprotect the worksheet, it doesn't prompt me for a
password. I've checked VB help, but still cannot find a solution. Below is
her script and the script I used to incorporate hers. Any help would be
appreciated :)

_JulieD
ThisWorkbook.Worksheets("Sheet1).Unprotect("YourPassword")
ThisWorkbook.Worksheets("Sheet1).Protect("YourPassword")

_Mine
Sub unpro_pro()
Range("B2").Select
Worksheets("sheet1").Unprotect Password:="YourPassword"
ActiveCell.FormulaR1C1 = "=R[1]C[4]"
Range("B2").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Worksheets("sheet1").Protect Password:="YourPassword"
End Sub
 
K

Ken Macksey

Hi

Instead of this,

Sub unpro_pro()
Range("B2").Select
Worksheets("sheet1").Unprotect Password:="YourPassword"
ActiveCell.FormulaR1C1 = "=R[1]C[4]"
Range("B2").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
Worksheets("sheet1").Protect Password:="YourPassword"
End Sub


Try it like this

Sub unpro_pro()
Range("B2").Select
Worksheets("sheet1").Unprotect Password:="YourPassword"
ActiveCell.FormulaR1C1 = "=R[1]C[4]"
Range("B2").Select
Worksheets("sheet1").Protect Password:="YourPassword",
DrawingObjects:=True, Contents:=True, Scenarios:=True

End Sub

I didn't check the Protect syntax for the order of the items following
protect, but it seemed to work for me.

HTH

Ken
 
K

Ken Macksey

To explain, basically when you tried to protect the sheet with a password,
the line before had already protected the sheet with no password. Hence no
password box if you clicked tools, unprotect sheet, because there was no
password.

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top