Password and Macro

W

Wanna Learn

Hello I have a workbook with several spreadsheets. I created a macro to
format a workshheet, e.g. copy and paste special values and protect the
worksheet with a password then go to another worksheet and protect the
worksheet with a password and return to the original worksheet. WHen I run
the macro everything is fine except that when I unprotect the worksheet it
does not ask me for a password but it unprotects the worksheets anyway I
don't want anyone to be able to unprotect these worksheets without the
password. Help and Thanks
 
M

Mike H

Without seeing the code it's hard to say what's going wrong but a sheet
password protected with code should ask for a password to un-protect it.

Try this:-

Sub protect()
ActiveSheet.protect Password:="mypass"
End Sub

Mike
 
W

Wanna Learn

Thanks Mike
Below is my code at the end of the macro, it seems I do not have a
password.... eventhough I had one when I recorded the macro)should I add your
code after "active sheet" in both places ?
Range("E2").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True,
AllowSorting _
:=True, AllowFiltering:=True
Sheets("PG Report ").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True
Sheets("Discount Grid").Select
Range("E2").Select
 
M

Mike H

Hi

Delete the bits after activesheet.protect so the code looks more like

Sub protect()
Range("E2").Select
ActiveSheet.protect Password:="mypass"
Sheets("PG Report ").Select
ActiveSheet.protect Password:="mypass"
Sheets("Discount Grid").Select
Range("E2").Select
End Sub
 
W

Wanna Learn

Mike PERFECT ! thanks a million

Mike H said:
Hi

Delete the bits after activesheet.protect so the code looks more like

Sub protect()
Range("E2").Select
ActiveSheet.protect Password:="mypass"
Sheets("PG Report ").Select
ActiveSheet.protect Password:="mypass"
Sheets("Discount Grid").Select
Range("E2").Select
End Sub
 

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