De: Tom Ogilvy Objet: Re: Excel hides a buttonCommand depending on the user Date : jeudi 14 septembre 2000 14:14 Here is one way to get the username: Paste the code in at the top of a new module. Declare Function WNetGetUser Lib "mpr.dll" _ Alias "WNetGetUserA" (ByVal lpName As String, _ ByVal lpUserName As String, lpnLength As Long) As Long Const NoError = 0 'The Function call was successful Sub prueba() MsgBox FindNetUserName End Sub Public Function FindNetUserName() As String Dim Netname As String Dim FileName As String ' Buffer size for the return string. Const lpnLength As Integer = 255 ' Get return buffer space. Dim status As Integer ' For getting user information. Dim lpName, lpUserName As String ' Assign the buffer size constant to lpUserName. lpUserName = Space$(lpnLength + 1) ' Get the log-on name of the person using product. status = WNetGetUser(lpName, lpUserName, lpnLength) ' See whether error occurred. If status = NoError Then ' This line removes the null character. Strings in C arenull- ' terminated. Strings in Visual Basic are not null-terminated. ' The null character must be removed from the C strings to be used ' cleanly in Visual Basic. lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1) Else ' An error occurred. lpUserName = "Unknown" End End If FindNetUserName = lpUserName End Function Regards, Tom Ogilvy MVP Excel "AAOmari" wrote in message news:20000913222138.11063.00000397@ng-fx1.aol.com... > I have an Excel File residing on a shared network drive. > I would like for Excel to hide a commnadbutton which (if clicked it will > execute a lengthy code to Get Data). Certain users with Read Only access should > not be able to run the Get Data code, they should be able to only view the > existing data. > > Other users should be able to run the Get Data code. > > Can, somehow, Excel know who the user is and hide the Get Data commandbutton if > the user is a Read Only user. > > Any ideas are welcome. >