Access to Command Buttons

Joe Carrigan

Board Regular
Joined
Oct 8, 2013
Messages
80
Hi everyone.
Sorry to bug you all at the weekend, I have a spreadsheet that I need everyone in the office to have access to. Unfortunately I also need to restrict access to the command buttons which are on one sheet. I know this is possible as I saw it done before, can somebody please help me to do this?

My list of valid user (using their windows username) is on sheet “Admin”, and the buttons are in sheet “Instructions”
Thanks in advance for your assistance.
PS Excel 2003
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
This will hide the buttons. Those that know what they are doing can still get to the code and run it, unless you've taken other steps such as passwording the code and setting the subs to private. (can they add their own name to the Admin list?) It's like putting a lock on the door, it will only keep the honest ones out. :)

Put this code in the Workbook_Open section. It will see if their Windows user ID is in the A column of the Admin page. If so, it will make the buttons visible. Of course, change your button names and ranges as necessary. You should start with the buttons invisible (put the code after "NotThere:" in the BeforeClose event to make sure they are by default).

Code:
Private Sub Workbook_Open()
On Error GoTo NotThere                                          'if the name is not found, it will error.  This will send it to error handling
If WorksheetFunction.Match(Environ("Username"), Sheets("Admin").Range("A1:A" & Sheets("Admin").Range("A" & Rows.Count).End(xlUp).Row), 0) Then
    With Sheets("Instructions")
        .OLEObjects("CommandButton1").Visible = True  'Shows the button.  Use this style if the buttons are Active X buttons
        .OLEObjects("CommandButton2").Visible = True
        .Buttons("Button 3").Visible = True                   'Shows the button.  Use this style if the buttons are Form Control buttons
    End With
End If
Exit Sub
NotThere:                                                            'Error handling
    With Sheets("Instructions")
        .OLEObjects("CommandButton1").Visible = False  'Hides the button.  Use this style if the buttons are Active X buttons
        .OLEObjects("CommandButton2").Visible = False
        .Buttons("Button 3").Visible = False                   'Hides the button.  Use this style if the buttons are Form Control buttons
    End With
On Error GoTo -1                                                   'resets the error handler
End Sub

I didn't try it on 2003, but I think it should work, nothing fancy here.
 
Upvote 0

Forum statistics

Threads
1,221,841
Messages
6,162,314
Members
451,759
Latest member
damav78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top