unprotect and protect within a macro

S

Staalkop

Hi XL freaks,
I am looking for a way to protect and unprotect a worksheet within a macro.
If I make the macro with the recording machine that is not possible.
The macro than runs but askes me to type in the password.
It is probably very easy, but too difficult for me, can anybody please
help ?
Thanks in advance,
Hans
 
Z

Zack Barresse

Hello Hans, fellow freak,


Option Explicit

Sub ProtectSheet()
Dim ws As worksheet
Set ws = Activesheet
ws.Protect "password"
End Sub

Sub UnprotectSheet()
Dim ws As worksheet
Set ws = Activesheet
ws.Unprotect "password"
End Sub


HTH
 
S

Staalkop

Staalkop schreef:
Hi XL freaks,
I am looking for a way to protect and unprotect a worksheet within a macro.
If I make the macro with the recording machine that is not possible.
The macro than runs but askes me to type in the password.
It is probably very easy, but too difficult for me, can anybody please
help ?
Thanks in advance,
Hans
Hi Zack, David and Alan,
thanks a lot : makes life a lot more easy !!!!
I finally used Alan's solution; quickest and easiest.
But thanks all of you for the effort,
Hans
 

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