View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Disable Tools Protection Protect Sheet for all users but one

Application.username
returns the name defined in Tools|Options|general

Maybe using the windows logon id would be better:

Option Explicit
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX < 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function

sub testme()
if lcase(fosusername) = "administrator" then
'do what you want
else
'don't do it
end if
end sub



Win XP wrote:

From other post I realize that you disable the menu item by:
Application.CommandBars("Tools").Controls("Protect ion").Enabled = False
but, I want to disable it for everyone unless you log on as Administrator.
I have tried the following, but it does not work.
Private Sub Workbook_Open()
If Application.UserName < "Administrator" Then
Application.CommandBars("Tools").Controls("Protect ion").Enabled = False
End If
End Sub
I cannot find the solution from other posts


--

Dave Peterson