Set password using macro

  • Thread starter Thread starter jempie
  • Start date Start date
J

jempie

i need to use a macro to set a password on a sheet. If i
try and record it, it locks the sheet without a password.
However, I need the sheet to have a set password (say
ABC).
 
Here are 2 that I use
Sub unprobook()

ActiveWorkbook.Unprotect password:="ABC"

End Sub

Sub probook()

ActiveWorkbook.Protect password:="ABC", Structure:=True,
Windows:=False

Good Luck

Mike

End Sub
 
Jempie,

This isn't really about a worksheet function (SUM(), etc), but here goes.

You're right -- it doesn't record the password. You can add it yourself:

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

Anyone who knows how to Alt-F11 (or other means) to the VBE can see the
password. That's likely why it doesn't record that part by default. You
can then lock the macros (In the VBE: Tools - Project Properties -
Protection - Lock project for viewing).
 
Back
Top