LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default password protection via code

Can anyone tell me where I am going wrong here? I have a multisheet workbook
that will be used by several people. I want to protect each sheet with a
password that will be based on the user. Each user's sheets will have a
similar naming criteria (e.g. Jenn's sheets will be named "PR.....", Riki's
will all be "CF....", etc.). I have code that looks at each sheet's name and
protects each sheet. However, I can't seem to get the password to be
applied. Also, the section that checks for protection isn't working, either

Any ideas? Here is the code I am using. I want to put this in the
Before_Close of the This Workbook...

Sub pword()

Dim I As Integer, ii As Integer, iSheets As Integer
Dim NN As String

iSheets = ActiveWorkbook.Sheets.Count

For ii = 1 To iSheets - 1 ' I don't want the last sheet protected here
Sheets(ii).Activate
If ActiveWorkbook.ActiveSheet.Protect = True Then GoTo skipme
'If sheet is already protected, don't bother
Select Case Left(ActiveWorkbook.ActiveSheet.Name, 2)
Case "PR"
NN = "jenn"
Case "CF"
NN = "riki"
Case "SD"
NN = "tric"
Case "LD"
NN = "luda"
Case Else
GoTo skipme
End Select

ActiveWorkbook.ActiveSheet.Protect Password:=NN, DrawingObjects:=True,
Contents:=True, Scenarios:=True

skipme:

Next ii

End Sub
--
Thanks in advance,

Bruce
swatsp0p
The older I get, the better I used to be.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password protection in macro ( Anybody can view my password in VB Sherees Excel Discussion (Misc queries) 2 January 24th 10 10:05 PM
Excel Data Protection- AKA: Sheet/Macro Password Protection Mushman(Woof!) Setting up and Configuration of Excel 0 December 29th 09 06:50 AM
PASSWORD PROTECTION JFW Excel Worksheet Functions 3 January 2nd 09 10:44 PM
Put Password Protection in Code Connie Excel Discussion (Misc queries) 3 October 25th 06 08:06 PM
VBA code delete code but ask for password and unlock VBA protection WashoeJeff Excel Programming 0 January 27th 04 07:07 AM


All times are GMT +1. The time now is 04:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"