Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Code for creating option buttons

Will really appreciate some help with this code for creating option buttons.

Option Explicit
Dim Sht As Worksheet
Dim buttonType
Dim leftPos As Integer
Dim topPos As Integer
Dim i As Integer

Sub Radio_Button_Create()
Set Sht = ThisWorkbook.Worksheets(1)
leftPos = 10
topPos = 10
For i = 1 To 10
buttonType = "Forms.OptionButton." & Format(i, "0")
topPos = topPos + 20
Sht.Shapes.AddOLEObject _
Left:=leftPos, _
Top:=topPos, _
Width:=8, _
Height:=8, _
ClassType:=buttonType
Next i
End Sub

It creates the first option button perfectly well but then fails on the
Sht.Shapes.AddOLEObject etc with Run time error 1004. Cannot insert object.

Regards,

OssieMac


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Code for creating option buttons

I assume you trying to create 10 option buttons and give each a known name:

Private Sub CommandButton2_Click()
Dim Sht As Worksheet
Dim i As Long
Dim OptButton As OLEObject

Const VERT_SPACE As Long = 20

Set Sht = ThisWorkbook.Worksheets(1)

For i = 1 To 10
Set OptButton = Sht.OLEObjects.Add( _
Left:=10, _
Top:=i * VERT_SPACE, _
Width:=8, _
Height:=8, _
ClassType:="Forms.OptionButton.1")

With OptButton
.Name = "MyOptionButton" & i
End With
Next i

End Sub

NickHK

"OssieMac" wrote in message
...
Will really appreciate some help with this code for creating option

buttons.

Option Explicit
Dim Sht As Worksheet
Dim buttonType
Dim leftPos As Integer
Dim topPos As Integer
Dim i As Integer

Sub Radio_Button_Create()
Set Sht = ThisWorkbook.Worksheets(1)
leftPos = 10
topPos = 10
For i = 1 To 10
buttonType = "Forms.OptionButton." & Format(i, "0")
topPos = topPos + 20
Sht.Shapes.AddOLEObject _
Left:=leftPos, _
Top:=topPos, _
Width:=8, _
Height:=8, _
ClassType:=buttonType
Next i
End Sub

It creates the first option button perfectly well but then fails on the
Sht.Shapes.AddOLEObject etc with Run time error 1004. Cannot insert

object.

Regards,

OssieMac




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Code for creating option buttons

A million thanks to you Nick. It works fine. I was certainly going along the
wrong path.

Regards,

OssieMac

"NickHK" wrote:

I assume you trying to create 10 option buttons and give each a known name:

Private Sub CommandButton2_Click()
Dim Sht As Worksheet
Dim i As Long
Dim OptButton As OLEObject

Const VERT_SPACE As Long = 20

Set Sht = ThisWorkbook.Worksheets(1)

For i = 1 To 10
Set OptButton = Sht.OLEObjects.Add( _
Left:=10, _
Top:=i * VERT_SPACE, _
Width:=8, _
Height:=8, _
ClassType:="Forms.OptionButton.1")

With OptButton
.Name = "MyOptionButton" & i
End With
Next i

End Sub

NickHK

"OssieMac" wrote in message
...
Will really appreciate some help with this code for creating option

buttons.

Option Explicit
Dim Sht As Worksheet
Dim buttonType
Dim leftPos As Integer
Dim topPos As Integer
Dim i As Integer

Sub Radio_Button_Create()
Set Sht = ThisWorkbook.Worksheets(1)
leftPos = 10
topPos = 10
For i = 1 To 10
buttonType = "Forms.OptionButton." & Format(i, "0")
topPos = topPos + 20
Sht.Shapes.AddOLEObject _
Left:=leftPos, _
Top:=topPos, _
Width:=8, _
Height:=8, _
ClassType:=buttonType
Next i
End Sub

It creates the first option button perfectly well but then fails on the
Sht.Shapes.AddOLEObject etc with Run time error 1004. Cannot insert

object.

Regards,

OssieMac





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
Creating a form with option buttons Jon[_21_] Excel Programming 3 April 15th 06 03:15 AM
Excel: creating a group of independent option buttons tD Excel Discussion (Misc queries) 3 December 22nd 05 07:52 AM
Navigating between option buttons is not selecting the option drhalter Excel Programming 1 June 3rd 05 02:28 PM
option buttons run Click code when value is changed via VBA code neonangel Excel Programming 5 July 27th 04 08:32 AM
Creating Buttons and assigning code winshent Excel Programming 3 July 14th 04 09:14 AM


All times are GMT +1. The time now is 03:51 AM.

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

About Us

"It's about Microsoft Excel"