rachelkirk
New Member
- Joined
- Jan 16, 2013
- Messages
- 18
I have been reading the post of "Rights Management" and I could not figure out why my code doesn't work.
For the 15 worksheets in the workbook, the management can read all while others can access only a number of them. There is a password to open the file. However, since the management do not want any password, I would like to use environ(username) to do this. I pasted the following code in the Workbook (Code), switch the should-be-"Very hidden" sheets to "Very hidden" but nothing happens. Please kindly help.
Option Explicit
Option Compare Text
Sub openup()
Dim vauth As Variant
Dim i As Integer
'Assume Not Authorsied
Sheets("1").Visible = True
Sheets("2").Visible = True
Sheets("3").Visible = True
Sheets("4").Visible = True
Sheets("6").Visible = True
Sheets("7").Visible = True
Sheets("8").Visible = True
Sheets("9").Visible = True
Sheets("10").Visible = xlVeryHidden
Sheets("11").Visible = True
Sheets("12").Visible = xlVeryHidden
Sheets("13").Visible = xlVeryHidden
Sheets("14").Visible = xlVeryHidden
Sheets("15").Visible = xlVeryHidden
Sheets("16").Visible = xlVeryHidden
Sheets("17").Visible = xlVeryHidden
Sheets("18").Visible = xlVeryHidden
Sheets("19").Visible = xlVeryHidden
Sheets("20").Visible = xlVeryHidden
Sheets("21").Visible = True
Sheets("22").Visible = xlVeryHidden
Sheets("23").Visible = True
who = LCase(Environ("username"))
vauth = Array("rachel", "patrick", "linda", "etc")
For i = LBound(vauth) To UBound(vauth)
If LCase(Environ("username")) = vauth(i) Then
'Deffo Authorised
Sheets("1").Visible = True
Sheets("2").Visible = True
Sheets("3").Visible = True
Sheets("4").Visible = True
Sheets("6").Visible = True
Sheets("7").Visible = True
Sheets("8").Visible = True
Sheets("9").Visible = True
Sheets("10").Visible = xlVeryHidden
Sheets("11").Visible = True
Sheets("12").Visible = True
Sheets("13").Visible = True
Sheets("14").Visible = True
Sheets("15").Visible = xlVeryHidden
Sheets("16").Visible = True
Sheets("17").Visible = True
Sheets("18").Visible = True
Sheets("19").Visible = True
Sheets("20").Visible = True
Sheets("21").Visible = True
Sheets("22").Visible = True
Sheets("23").Visible = True
Exit Sub ' if you don't intend to do anything else in this sub
End If
Next i
End Sub
For the 15 worksheets in the workbook, the management can read all while others can access only a number of them. There is a password to open the file. However, since the management do not want any password, I would like to use environ(username) to do this. I pasted the following code in the Workbook (Code), switch the should-be-"Very hidden" sheets to "Very hidden" but nothing happens. Please kindly help.
Option Explicit
Option Compare Text
Sub openup()
Dim vauth As Variant
Dim i As Integer
'Assume Not Authorsied
Sheets("1").Visible = True
Sheets("2").Visible = True
Sheets("3").Visible = True
Sheets("4").Visible = True
Sheets("6").Visible = True
Sheets("7").Visible = True
Sheets("8").Visible = True
Sheets("9").Visible = True
Sheets("10").Visible = xlVeryHidden
Sheets("11").Visible = True
Sheets("12").Visible = xlVeryHidden
Sheets("13").Visible = xlVeryHidden
Sheets("14").Visible = xlVeryHidden
Sheets("15").Visible = xlVeryHidden
Sheets("16").Visible = xlVeryHidden
Sheets("17").Visible = xlVeryHidden
Sheets("18").Visible = xlVeryHidden
Sheets("19").Visible = xlVeryHidden
Sheets("20").Visible = xlVeryHidden
Sheets("21").Visible = True
Sheets("22").Visible = xlVeryHidden
Sheets("23").Visible = True
who = LCase(Environ("username"))
vauth = Array("rachel", "patrick", "linda", "etc")
For i = LBound(vauth) To UBound(vauth)
If LCase(Environ("username")) = vauth(i) Then
'Deffo Authorised
Sheets("1").Visible = True
Sheets("2").Visible = True
Sheets("3").Visible = True
Sheets("4").Visible = True
Sheets("6").Visible = True
Sheets("7").Visible = True
Sheets("8").Visible = True
Sheets("9").Visible = True
Sheets("10").Visible = xlVeryHidden
Sheets("11").Visible = True
Sheets("12").Visible = True
Sheets("13").Visible = True
Sheets("14").Visible = True
Sheets("15").Visible = xlVeryHidden
Sheets("16").Visible = True
Sheets("17").Visible = True
Sheets("18").Visible = True
Sheets("19").Visible = True
Sheets("20").Visible = True
Sheets("21").Visible = True
Sheets("22").Visible = True
Sheets("23").Visible = True
Exit Sub ' if you don't intend to do anything else in this sub
End If
Next i
End Sub