Previous posts on this subject:
Creating a CheckBox
Until now, all the posts have focussed on creating buttons in a variety of styles, shapes and sizes. Today, we'll take a look at a simple example of a checkbox. What we'll do is create a single checkbox on a custom tab.
The XML to create a checkbox is once again similar to what we've seen. One big difference is that we cannot use a picture, of course, since the actual check box will take it's place. The XML for our test is as follows:
This will create a custom tab called "XLG", and on it will be the lonely control as shown below:
Now, the checkbox is there, but we need to be able to figure out if it is clicked. If you recall Part 1 of this series, we set up a routine called "CallControl" (specified in our XML), that started like this:
[vb]Private Sub CallControl(Control As IRibbonControl)[/vb]
To determine the value of the checkbox, however, we need a slightly expanded VBA routine. We still use the basic framework as above, but we expand it to also pick up the "Pressed" portion as shown below:
[vb]Private Sub CallControl(control As IRibbonControl, pressed As Boolean)
'Tell the user the state of the control when they physically click it.
Select Case pressed
MsgBox "The checkbox is checked!"
MsgBox "The checkbox is NOT checked!"
Again, the code above goes in a standard module. Once you have it there, try clicking the checkbox on the Ribbon, and notice that it will feed back if it is checked or not.
This example is educational only, of course. In a real setting you would replace the message boxes with code that you would wish to execute based on the user's selection.
In the next part, we will look at how to toggle the values of the checkbox via code, and have it update the Ribbon automatically... stay tuned! 🙂