LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Different passwords to separate ranges in excel 2000

Actually I needed the Workbook_Open event, and had to code it (figure
it out myself, couldn't find info on this, just a bit on protection)

I'm using a UserForm to ask for the password (it's name's PassForm
called on the Workbook_Open event.

I defined 4 ranges, each range start has a particular name followe
with a S (RegistroS for example) and the range end ends with an
(RegistroE), the reason I named the worksheet columns like this i
that, in case adding columns were necessary, the code wouldn't have t
change.

Here's the PassForm code:



Function WorksheetAccess(Area)
Dim sh As Worksheet
Dim SanLocked, RegLocked, CarLocked, MinLocked As Boolean
Dim TextoSaludo As String
Select Case Area
Case "san"
SanLocked = False
RegLocked = True
CarLocked = True
MinLocked = True
TextoSaludo = "Usted tiene acceso al área de Saneamiento"
Case "reg"
SanLocked = True
RegLocked = False
CarLocked = True
MinLocked = True
TextoSaludo = "Usted tiene acceso al área de Registro"
Case "car"
SanLocked = True
RegLocked = True
CarLocked = False
MinLocked = True
TextoSaludo = "Usted tiene acceso al área de Cartera"
Case "min"
SanLocked = True
RegLocked = True
CarLocked = True
MinLocked = False
TextoSaludo = "Usted tiene acceso al área de Minutación"
Case "sis"
SanLocked = False
RegLocked = False
CarLocked = False
MinLocked = False
TextoSaludo = "Usted tiene acceso total"
Case Else
SanLocked = True
RegLocked = True
CarLocked = True
MinLocked = True
TextoSaludo = "Usted no tiene permiso para editar est
documento"
End Select
For Each sh In ThisWorkbook.Worksheets
With sh
.Activate
.Unprotect "JUANCHO"
.Range("SaneamS,SaneamE").Locked = SanLocked
.Range("RegistroS,RegistroE").Locked = RegLocked
.Range("CarteraS,CarteraE").Locked = CarLocked
.Range("MinutacionS,MinutacionE").Locked = MinLocked

.EnableAutoFilter = True
If Area < "sis" Then
.Protect Password:="JUANCHO", UserInterfaceOnly:=True
Application.CommandBars("tools").Controls("Macro") .Enabled = False
Application.CommandBars("tools").Controls("compart i
libro...").Enabled = False
Application.CommandBars("tools").Controls("control d
cambios").Enabled = False
Application.CommandBars("tools").Controls("protege r").Enabled
False
End If
End With

Next
PassForm.Hide
MsgBox TextoSaludo
End Function



Private Sub PassButton_Click()
Select Case TextBox1.Text
Case "1"
WorksheetAccess ("san")
Case "2"
WorksheetAccess ("reg")
Case "3"
WorksheetAccess ("car")
Case "4"
WorksheetAccess ("min")
Case "sistemas"
WorksheetAccess ("sis")
Case Else
MsgBox "Contraseña incorrecta"
TextBox1.SetFocus
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)

End Select

End Sub


Private Sub UserForm_Terminate()
WorksheetAccess ("none")
End Sub



Now, this is strange indeed, I tried wit
ThisWorkbook.Application.CommandBars but it affects other exce
workbooks as well, So I enable again on the beforeclose event...

If you've got any suggestions to improve this code I'd appreciat
them.

Hope this can be of use

--
Message posted from http://www.ExcelForum.com

 
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
Average Ranges of Cells, Return Separate Value for Each Range Eric H Excel Worksheet Functions 5 October 19th 09 04:39 PM
Named ranges prints on separate pages Don Rowley Excel Discussion (Misc queries) 0 January 4th 08 06:15 PM
Can I create Multiple passwords to edit multiple ranges? Conker10382 Excel Discussion (Misc queries) 8 December 31st 06 07:58 PM
2 separate passwords (both valid) to open file regi Excel Discussion (Misc queries) 3 October 2nd 06 04:55 PM
how to select two separate ranges into range object Serge[_2_] Excel Programming 2 October 1st 03 03:10 PM


All times are GMT +1. The time now is 04:05 AM.

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

About Us

"It's about Microsoft Excel"