Change ribbon toggle button state

Rolly_Sefu

Board Regular
Joined
Oct 25, 2013
Messages
149
Hello I have a toggle button added to the ribbon (xml way)

and I have the following code:

Code:
Sub ribbonbutton1(control As IRibbonControl, ByRef cancelDefault)
    If Sheets("Database").Range("I2") = "Yes" Then           'check if master
        If Sheets("Database").Range("I4") <> "Yes" Then    'check if button is pressed
            Sheets("Database").Range("I4") = "Yes"              'declare button is pressed Yes
            Sheets("Board").Visible = True
        Else
            Sheets("Database").Range("I4") = ""                   'reset pressed status to no
            Sheets("Board").Visible = xlVeryHidden
        End If
    Else
        MsgBox "You do not have the permission to make this change !", vbCritical, "STOP"
        State = False  ' => this does not work
    End If
 End Sub

I have created this button to add a functionality for a number of user that access the file.

The user that presses the button does not have the right to change, gets the error message.
But the button remains press. - this is the problem

And I can not figure out how to make the "State = False" work.

Help please.
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Here is the xml code if it helps

HTML:
<!--RibbonX Visual Designer 1.94 for Microsoft Excel 16.0. XML Code produced on 2018.04.20-->
<customUI  xmlns="http://schemas.microsoft.com/office/2006/01/customui" >
 <ribbon >
  <tabs >
   <tab 
    id="Tab1"
    insertBeforeMso="TabHome"
    label="CM">
    <group 
     id="Group1"
     label="General">
     <toggleButton 
      id="Togglebutton1"
      imageMso="AutoSum"
      label="Master"
      size="large"
      getPressed="ribbonbutton11"
      onAction="ribbonbutton1"/>
    </group >
   </tab >
  </tabs >
 </ribbon >
</customUI >
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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