Hello.
Thanks a lot for the reply's on this thread they where, very useful, especially the excel files.
I also create a version for my needs.
i made the code protect and unprotect the active sheet based on the button click.
The problem is that the workbook has multiple sheets and i wanted to buttons to change based on the selection of the sheet, if it is protected or not.Option Explicit Public gobjRibbon As IRibbonUI Public B1 As Boolean, B2 As Boolean Public Sub OnRibbonLoad(objRibbon As IRibbonUI) Set gobjRibbon = objRibbon If ActiveSheet.ProtectContents = True Then B1 = True B2 = False Else B1 = False B2 = True End If End Sub 'Callback for customButton1 onAction Sub Pushed(control As IRibbonControl, pressed As Boolean) Dim user, x As String user = Environ("Username") On Error Resume Next x = Application.WorksheetFunction.VLookup(user, Sheets("Stuff").Range("Login"), 1, False) Select Case control.ID Case "Togglebutton1" If Err.Number > 0 Then MsgBox "I'm sorry, you do not have access to LOCK this file !", vbCritical B1 = True B2 = False Else On Error GoTo 0 ActiveSheet.Protect Password:=pwd, DrawingObjects:=False, Contents:=True, Scenarios:=True, AllowSorting:=True, AllowFiltering:=True B1 = True B2 = False End If Case "Togglebutton2" If Err.Number > 0 Then MsgBox "I'm sorry, you do not have access to UNLOCK this file !", vbCritical B1 = True B2 = False Else On Error GoTo 0 ActiveSheet.Unprotect Password:=pwd B1 = False B2 = True End If End Select gobjRibbon.Invalidate End Sub 'Callback for customButton1 getPressed Sub UpOrDown(control As IRibbonControl, ByRef returnedVal) Select Case control.ID Case "Togglebutton1" returnedVal = B1 Case "Togglebutton2" returnedVal = B2 End Select End Sub
VBA i placed into the worksheets:
The code runs OnRibbonLoad, but i get an error for UpOrDownPrivate Sub Worksheet_Activate() Dim FakeControl As IRibbonControl Module3.OnRibbonLoad FakeControl Module3.UpOrDown FakeControl End Sub
Help please.




