From: PawlingJohn on
How do I insert a 2 radio button group using Excel 2007 and of course how do
i program them?

thank you in advance.
From: Chip Pearson on
The following code will create a Frame and two Option Buttons at cell
C3. Change the various Top and Left properties to get them positioned
as you want.

Sub AAA()
Dim FRA As OLEObject
Dim BTN1 As OLEObject
Dim BTN2 As OLEObject
Dim WS As Worksheet
Dim TopLeftCell As Range
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim N As Long

Set WS = Worksheets("Sheet1")
Set TopLeftCell = WS.Range("C3")
With TopLeftCell
Set FRA = WS.OLEObjects.Add(classtype:="Forms.Frame.1", _
Left:=.Left, Top:=.Top, Width:=150, Height:=100)
End With

FRA.Object.Caption = "Select"
Set BTN1 = WS.OLEObjects.Add(classtype:="Forms.OptionButton.1", _
Left:=FRA.Left + 10, Top:=FRA.Top + 10, Width:=60, Height:=20)
BTN1.Name = "optButton1"

Set BTN2 = WS.OLEObjects.Add(classtype:="Forms.OptionButton.1", _
Left:=FRA.Left + 10, Top:=BTN1.Top + 30, Width:=60,
BTN2.Name = "optButton2"

Set VBComp = ThisWorkbook.VBProject.VBComponents( _
Set CodeMod = VBComp.CodeModule
N = CodeMod.CreateEventProc("Click", BTN1.Name)
CodeMod.InsertLines N + 1, " MsgBox ""Hello World 1"""
N = CodeMod.CreateEventProc("Click", BTN2.Name)
CodeMod.InsertLines N + 1, " MsgBox ""Hello World 2"""
End Sub

This code will also create the event procedures (the Click event) for
the two buttons. In the Sheet1 code module, the following code is

Private Sub optButton1_Click()
MsgBox "Hello World 1"
End Sub

Private Sub optButton2_Click()
MsgBox "Hello World 2"
End Sub

You'll need a reference to the extensibility library. In VBA, go to
the Tools menu, choose References, and scroll down to and check the
entry for "Microsoft Visual Basic For Applications Extensibility
Library 5.3".

Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC

On Fri, 9 Apr 2010 09:39:01 -0700, PawlingJohn
<PawlingJohn(a)> wrote:

>How do I insert a 2 radio button group using Excel 2007 and of course how do
>i program them?
>thank you in advance.