Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I add a radio button, check box, etc. in excel 2007? | Excel Discussion (Misc queries) | |||
HELP radio button not functioning in Excel 2007 | Excel Programming | |||
How do I insert radio button to sum a cell when clicked | Excel Worksheet Functions | |||
How do I insert a radio button into a spreadsheet? | Excel Discussion (Misc queries) | |||
VBA: Disable Frame and Radio Buttons based on Another Radio Button Being True | Excel Worksheet Functions |