Link to home
Start Free TrialLog in
Avatar of rsen1
rsen1

asked on

Workbook vba protection with password

Please offer suggestions for Vba code to password protect a workbook with EnableAutoFilter = True added to the protectio.

Thank you
Avatar of dlmille
dlmille
Flag of United States of America image

Which sheets to do you want to password protect and add EnableAutoFilter on?

Or do you want to protect the entire workbook?  You really should do that with the save password, correct?

Dave
Avatar of rsen1
rsen1

ASKER

Dave, thank you for your response. Whjat is meant by the save password?
let me ask again.

Do you just want to add filtering to the existing protected sheets, and also a password to those sheets?

Dave
Avatar of rsen1

ASKER

Sheets that need password and  EnableAutoFilter on
Labor
Roster
converter
input 1-20
input 21-40
ASKER CERTIFIED SOLUTION
Avatar of dlmille
dlmille
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note, the password is hardcoded in the code (first line), so pretty easy for users to get at, but if this is just a reminder that they don't have access and you want to trouble them not to unlock the sheet, then you're ok.  Excel/Office is fairly notorious for weak security when it comes to stuff like this.

Cheers

Dave
Avatar of rsen1

ASKER

Dave that works great, thank you.

Why would l not want this workbook set to this password code on open and if it were set for workbook change would have the same effect on the copy paste as it did sitting on the sheet code?
Robert
I'm not sure exactly what you said. I was just saying that any user can go to VBA to see the password.  Do you need more security than this?

Dave
Avatar of rsen1

ASKER

I can set the vba password.

I was curious for the reason to set this password in
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
rather than
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Why continuously set the password?  SheetChange would do it everytime the cursor changed from one cell to the next.

it really only need be set by the person that has password access to change the format of the workbook.  Once everything is protected, no code really need be run afterward.  In fact, you could protect everything from another workbook and this one have no code at all, lol.

However, what this allows the way its currently coded, is for you to unprotect a tab manually, then when the workbook is saved, everything is made under wraps again.

It really doesn't matter that that code runs when the user saves (because everything is ALREADY protected), its just redundant at that point.

Make sense?

Dave
Avatar of rsen1

ASKER

Thank you Dave very much. You were a huge help.