The information in this article applies to:
SUMMARYThere are two ways to group option buttons on a UserForm. To group the controls, do either of the following:
Neither method is better than the other one. The method you choose depends on how you want to implement the project and whether you want to use a Frame control for each group on the UserForm or use macro code. This article contains macro examples that use both methods. This article also contains an example that illustrates a third method that does not require grouping of option buttons. MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to provide added
functionality or construct procedures to meet your specific needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.asp Using a Frame Control to Group Option ButtonsIn this example, you create a UserForm that contains a command button, and three option buttons within a Frame control. The advantage of having the option buttons within the frame is that the Frame control creates a collection of controls for the frame. This collection of option buttons in the Frame control works well with the For Each...Next loop.
The UserForm is displayed with none of the option buttons selected. A message box appears with the caption of the currently selected option button. Using the GroupName Property to Create Option Button GroupsIf you do not use a Frame control to group your option buttons, then it is harder to programmatically determine which option button is the selected option. You can set the GroupName property for a set of option buttons to the same value. This ensures that if you click one option button the other buttons are turned off (all option buttons in a group are mutually exclusive). However, you must determine which option button is the one that is turned on.
NOTE: The macro provided below does not address this second group. It is added to the UserForm to illustrate how to programmatically identify option buttons in specific groups (in this case, in "mygroup1").
The UserForm appears. A message box appears and displays the caption of the currently selected option button from mygroup1. Setting a Global Variable to the Name of the Selected OptionA third method for working with option buttons on a UserForm requires neither a Frame control nor a common GroupName. This method uses macro code, which is assigned to the Click event for each option button you create on the UserForm, to set the value of a global variable to the name of the selected option button. If you create multiple groups of option buttons, you can use a different global variable for each group.
This step displays the code module that is associated with the UserForm.
This step displays the code module associated with the UserForm.
This step displays the code module that is associated with the UserForm.
Your UserForm appears. A message box appears that displays the name of the selected option button. REFERENCESFor more information about grouping option buttons, in the Visual Basic Editor, click
Microsoft Visual Basic Help on the Help menu, type
groupname property in the Office Assistant or the Answer Wizard, and
then click Search to view the topic. Additional query words: XL2000
Keywords : kbprg kbdta kbdtacode KbVBA |
Last Reviewed: December 13, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |