Loop with activeX optionbuttons.

J

Jan Vente

Dear listmembers,

In a spreadsheet with activeX optionbuttons (not the "old" forms
optionbuttons). A macro renames the name of the object en places the new
name in de caption of the optionbutton. In this loop some of the names and
the captions are mixed. The controls get the correct names, but get a wrong
caption. If I fysically rearrange the optionbuttons in the order of the
captions, the macro still mixes up the same names and captions. In the
listing below you will find a simplified example of the code.
It the problem exist by 15 of 300 optionbuttons.
I'll hope you will understand the problem en could help me.

TIA Jan Vente

dim oleObj as OLEobject
dim optObj as msforms.optionbutton
dim wsV as Worksheet
dim intX as integer

set wsV = worksheets("Vragen")
intX = 1
For Each oleObj In wsV.OLEObjects
If TypeOf oleObj.Object Is MSForms.OptionButton Then
Set optObj = oleObj.Object
oleObj.Visible = True
strNaam = "opt" & str(intX)
oleObj.Name = strNaam
optObj.Caption = strNaam
intX = intX +1
end if
Next oleObj
 
J

Jim Cone

Jan,
Add "Option Explicit" as the first line in the module and see what happens.
Regards,
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


In a spreadsheet with activeX optionbuttons (not the "old" forms
optionbuttons). A macro renames the name of the object en places the new
name in de caption of the optionbutton. In this loop some of the names and
the captions are mixed. The controls get the correct names, but get a wrong
caption. If I fysically rearrange the optionbuttons in the order of the
captions, the macro still mixes up the same names and captions. In the
listing below you will find a simplified example of the code.
It the problem exist by 15 of 300 optionbuttons.
I'll hope you will understand the problem en could help me.
TIA Jan Vente


dim oleObj as OLEobject
dim optObj as msforms.optionbutton
dim wsV as Worksheet
dim intX as integer
set wsV = worksheets("Vragen")
intX = 1
For Each oleObj In wsV.OLEObjects
If TypeOf oleObj.Object Is MSForms.OptionButton Then
Set optObj = oleObj.Object
oleObj.Visible = True
strNaam = "opt" & str(intX)
oleObj.Name = strNaam
optObj.Caption = strNaam
intX = intX +1
end if
Next oleObj
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top