PDA

View Full Version : Compile Error



Pete
07-21-2008, 11:55 PM
Hi

I am getting a compile error on the following code i have added to the worksheet "Administrator" in my workbook.

Sub Worksheet_Activate()
If fOSUserName <> 'Insert your UserName here as string Then
MsgBox "You are not authorized to view this worksheet."
End If
End Sub

Bob Phillips
07-22-2008, 12:27 AM
Sub Worksheet_Activate()
If fOSUserName <> "Insert your UserName here as string" Then
MsgBox "You are not authorized to view this worksheet."
End If
End Sub


What is fOSUserName, how does it get set? Shouldn't you activate some other sheet after that condition is met, and skip the MsgBox?

Pete
07-22-2008, 12:31 AM
let me post te work book......having a bad day.....one of those days...

Bob Phillips
07-22-2008, 12:35 AM
Exac tly as I said, and all the same questions apply.

mdmackillop
07-22-2008, 05:32 AM
Sub CheckUser()
Dim nm As String, arr, tmp As Long
nm = Application.UserName
arr = Array("Bert", "Fred", "Willie", "MD")
On Error Resume Next
tmp = Application.Match(nm, arr, 0)
If tmp = 0 Then
MsgBox "You cannot open this sheet"
Else
MsgBox "Opening sheet"
End If
End Sub