View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
e e is offline
external usenet poster
 
Posts: 18
Default Novice - using macro to protect with password

Good plan, thanks. I assume 'demo2' is the name of the macro, which I can
change, and then add in a shortcut in the Options menu? (I'm Office 2007.)

"Sam Wilson" wrote:

You might want to add a second macro to unprotect all sheets:

Sub demo2()

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Unprotect "blahblah"
Next ws

End Sub

Sam


"E" wrote:

Wow, that seems to be just the ticket! I will try fiddling with it to
customise. Many thanks!

"Sam Wilson" wrote:

Hi,

Press Alt + F11 to show the VB Editor window. Find "Book1" or whatever your
workbbok is called, and right-click it to "Insert Module" - paste this into
the module:

Sub demo()

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Protect "blahblah"
Next ws

End Sub

changing "blahblah" to whatever password you want.

That's it.

Sam


"E" wrote:

I want to protect every sheet in a workbook with a password. I understand
this is tricky, so I will be satisfied if I can write a macro to password
protect every sheet, which will save me typing in the password twice for
every sheet.
I have used macros before by simply recording them, but have no idea how to
write the code myself. Please could someone give me some very simple
instructions how to write an appropriate macro, or edit one I can easily
record.

Thanks.