"R_" at the start allows the user to easily filter for only the ribbon items.These objects make it very easy to read or write ribbon item properties with VBA code. These names are computer generated and when you publish it, Easy Ribbon Builder will define all ribbon items as objects using these names. This example code below greys out buttons depending on what sheet is selected.Īs you develop your ribbon with Easy Ribbon Builder you'll notice that there is a column titled 'VBA object name'. (Optional) Add code to set rules for dynamic changes to your ribbon.
So in this example I typed "R_J" then "CTRL + space" then the full name "R_Joke_G1B2" was inserted. If you type in enough text that it is unique to a button object name then its full object name will be inserted. Anywhere in VBA just type "CTRL + Space" then start typing in your button label to find it. Note 2 - Finding a button object name in VBA This method is robust as the Control ID is unique and fixed Method 2: If ButtonItem.ControlID = R_Joke_G1B2.ControlID Then
If the Label changes name or if the button has the same label as another button then you can get errors. Method 1: If ButtonItem.Label = "Joke" then MsgBox "Incorrect" & vbNewLine & vbNewLine & "Answer: The women spit further.", Title:="Classic Joke" MsgBox "You got it correct!", Title:="Classic Joke" If InStr(jokeInput, "pull the pin and throw it back") > 0 Then JokeInput = InputBox(" What should you do if an Aussie throws a grenade at you?", Title:="Classic Joke") If ButtonItem.ControlID = R_Joke_G1B2.ControlID Then Public Sub Button_Click(ButtonItem As Variant)
Or just click on any of your ribbon buttons to take you to the Button_Click procedure directly. Click 'My_Code' module > scroll down to Button_Click.