Use VB to unlock & lock cell protection

V

Vacuum Sealed

Hi everyone

was wondering if anyone out there was able to fill in the blanks for me
please.

Using VB

Turn this:

ActiveSheet.Unprotect.
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

into something like this:

Sub()

Application.ScreenUpdating = False

ActiveSheet.Unprotect.Password: = "myPassword"

------>ActiveSheet.DoMyThing

ActiveSheet.Protect.Password: = "myPassword", ReConfirm_Password: =
"myPassword", DrawingObjects:=True, Contents:=True, Scenarios:=True

------>DoMyOtherThing

Application.ScreenUpdating = True

End Sub

So the idea here that the user clicks Macro button, it opensTargetWB,
activatesTargetWS, removes cell protections, pastes values, re-applies cell
protection, then closesWB, all within the blink of an eye never knowing that
the cell protection was touched.

Ideas & Suggestions welcomed

TIA
Mick
 
A

Alan

Hi everyone

was wondering if anyone out there was able to fill in the blanks for me
please.

Using VB

Turn this:

ActiveSheet.Unprotect.
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

into something like this:

Sub()

Application.ScreenUpdating = False

ActiveSheet.Unprotect.Password: = "myPassword"

------>ActiveSheet.DoMyThing

ActiveSheet.Protect.Password: =  "myPassword", ReConfirm_Password: =
"myPassword", DrawingObjects:=True, Contents:=True, Scenarios:=True

------>DoMyOtherThing

Application.ScreenUpdating = True

End Sub

So the idea here that the user clicks Macro button, it opensTargetWB,
activatesTargetWS, removes cell protections, pastes values, re-applies cell
protection, then closesWB, all within the blink of an eye never knowing that
the cell protection was touched.

Ideas & Suggestions welcomed

TIA
Mick

Sub()

Const PW as string="MyPassword"

Application.ScreenUpdating = False

ActiveSheet.Unprotect Password:= PW
------>ActiveSheet.DoMyThing

ActiveSheet.Protect Password:= PW, DrawingObjects:=True,
Contents:=True, Scenarios:=True

------>DoMyOtherThing

Application.ScreenUpdating = True

End Sub

You may need to take steps such that the password can't be simply
looked up, i.e. protect the code.

A.
 

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