Not having to enter PW

Colleen45

Active Member
Joined
Jul 22, 2007
Messages
495
I have macro that is run when certain names are selected from a drop down list
However I don't want the users of this workbook having to enter a PW
Yet the PW is required for the macro to run, is there a way?

I recorded a macro where I entered the PW, and rentered it again just before the end of the macro to lock the worbook up again, yet when the macro runs it asks for the pw
How do I bypass this and still have the worked locked after running the Maco

This the recorded macro:

[bb]
Sub unhide_rows()
'
' unhide_rows Macro
'

'
ActiveSheet.Unprotect
ActiveWindow.DisplayHeadings = True
Rows("10:15").Select
Range("A15").Activate
Selection.EntireRow.Hidden = False
Rows("16:16").Select
Range("AD16").Activate
ActiveWindow.DisplayHeadings = False
Range("A19:D19").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
[/bb]
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi Colleen,

Rather that ActiveSheet, Set a reference to the sheet in question. For the Password issue, in vba help, look at .Protect and .Unprotect. The password may be included as a string so that the user does not get asked.

Hope that helps,

Mark
 
Upvote 0
Yes :-)

You can use:
Code:
ThisWorkbook.Worksheets("MySheet").Unprotect Password:="MyPassword"
or, using the sheet's codename:
Rich (BB code):
Sheet1.Unprotect Password:="MyPassword"
Sheet1.Protect Password:="MyPassword", DrawingObjects:=True, Contents:=True, Scenarios:=True
You may also wish to try skipping the unprotect line and re-applying the protect in its place, supplying the UserInterfaceOnly arg.
Rich (BB code):
Sheet1.Protect Password:="MyPassword", DrawingObjects:=True, _
               Contents:=True, Scenarios:=True, UserInterfaceOnly:=True

UserInterfaceOnly keeps the sheet protected, but allows the code to make changes. An advantage is that even if the code fails midway, the sheet has never been unprotected to the user.
 
Upvote 0
I would prefer the second option you gave,
How would I add that to the original post from the 1st post.

also what springs to mind is, what stops some "smarty" user looking at the code and simply reading off the password.

There's nothing special in the workbook that has to be hidden, it's just to protect all the code and formulas from acidental erasure
 
Upvote 0
Okay, I've got this working perfectly, thank you so much for your help. Just one question remains. How do I stop someone simply reading the password off from the code?
 
Upvote 0
Okay, I've got this working perfectly, thank you so much for your help. Just one question remains. How do I stop someone simply reading the password off from the code?

Protect the VB Project. Tools-->VBA Project Properties-->Protection-->Lock project for viewing and add a password.

HTH,
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top