your image

Creating a Check Box - MS-Excel Tutorial

sourcedaddy
Related Topic
:- MS Excel

Creating a Check Box

If you have a macro that toggles some setting on or off, then a button or menu element isn't a great choice as a front-end for the macro because these elements have no way of showing the current state of the setting. A much better choice would be a check box: When it's checked, the setting is activated; when it's unchecked, the setting is deactivated.

You create the check box control by using the <checkBox> element:

<checkBox id="value"label="value"InsertAfterMso="value"InsertBeforeMso="value"onAction="value"enabled="true|false"visible="true|false"screentip="value"supertip="value"keytip="value">

For example, the following XML code creates a check box that, when clicked, runs a macro named chkToggleProofingErrors_OnAction:

<checkbox id="chkToggleProofingErrors"label="Show Proofing Errors"onAction="Module1.chkToggleProofingErrors_OnAction" />

Here's the chkToggleProofingErrors_OnAction macro:

Sub chkToggleProofingErrors_OnAction(ByVal control As IRibbonControl, pressed As Boolean)With ActiveDocument.ShowSpellingErrors = pressed.ShowGrammaticalErrors = pressedEnd WithApplication.ScreenRefreshEnd Sub

Notice that the Sub statement includes not only the IRibbonControl object, but also a Boolean variable named pressed. This variable passes to the macro the current state of the check box control: pressed is True when the check box is activated, and it's False when the check box is deactivated. In this case, you use the pressed value to toggle the active document's ShowSpellingErrors and ShowGrammaticalErrors properties on and off.

Comments