Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default How do I insert a radio button using Excel 2007?

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,
Height:=20)
BTN2.Name = "optButton2"

Set VBComp = ThisWorkbook.VBProject.VBComponents( _
TopLeftCell.Worksheet.CodeName)
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
generated:

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".

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com













On Fri, 9 Apr 2010 09:39:01 -0700, PawlingJohn
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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I add a radio button, check box, etc. in excel 2007? Andrew Excel Discussion (Misc queries) 2 January 21st 10 06:16 AM
HELP radio button not functioning in Excel 2007 Twishlist Excel Programming 1 June 17th 08 01:43 PM
How do I insert radio button to sum a cell when clicked Joe D. Excel Worksheet Functions 1 March 6th 06 08:54 PM
How do I insert a radio button into a spreadsheet? Boyce Excel Discussion (Misc queries) 2 June 9th 05 01:55 PM
VBA: Disable Frame and Radio Buttons based on Another Radio Button Being True Mcasteel Excel Worksheet Functions 2 October 29th 04 07:06 PM


All times are GMT +1. The time now is 06:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"