PC Review


Reply
Thread Tools Rate Thread

Code for creating option buttons

 
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      23rd Mar 2007
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 With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      23rd Mar 2007
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" <(E-Mail Removed)> wrote in message
news:A3EFE30D-5846-492D-80FD-(E-Mail Removed)...
> 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 With Quote
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      23rd Mar 2007
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" <(E-Mail Removed)> wrote in message
> news:A3EFE30D-5846-492D-80FD-(E-Mail Removed)...
> > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a form with option buttons Jon Microsoft Excel Programming 3 15th Apr 2006 03:15 AM
Need help on creating option buttons on Form CAD Fiend Microsoft Access Forms 0 25th Jul 2005 02:13 PM
Creating a Form Using Option Buttons =?Utf-8?B?ZHNhdXNzYXll?= Microsoft Word Document Management 0 2nd Nov 2004 06:44 PM
option buttons run Click code when value is changed via VBA code neonangel Microsoft Excel Programming 5 27th Jul 2004 08:32 AM
Creating new Option buttons Seamus McMillan Microsoft Excel Worksheet Functions 1 16th Sep 2003 02:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:55 PM.