OptionButton in a Frame not visible

G

Guest

Hi,

I am using the attached code to generate a Form, a Frame, and
an OptionButton.

When the Form is shown, the OptionButton is not visible.
I played with other components inside a Frame, and the problem
persisted.

I am running Excel XP on Windows XP.

Thanks, JoeBen

=====
Sub Test()

Dim uiForm1 As Object
Set uiForm1 = ActiveWorkbook.VBProject.VBComponents.Add(3)
With uiForm1
.Properties("Caption") = "uiForm1"
.Properties("Left") = 11
.Properties("Top") = 22
.Properties("Width") = 444
.Properties("Height") = 333
End With

Dim uiFrame1 As MSForms.Frame
Set uiFrame1 = _
uiForm1.Designer.Controls.Add("Forms.Frame.1")
With uiFrame1
.Caption = "uiFrame1"
.Left = 31
.Top = 42
.Width = 404
.Height = 253
End With

Dim uiOptionButton1 As MSForms.OptionButton
Set uiOptionButton1 = _
uiForm1.Designer.Controls.Add("Forms.OptionButton.1")
With uiOptionButton1
.Caption = "uiOptionButton1"
.Left = 51
.Top = 62
.Width = 40
.Height = 30
End With

Dim uisheet1 As Worksheet
Set uisheet1 = Sheets.Add
With uisheet1
.Name = "uisheet2"
End With

Dim uiCommandButton1 As OLEObject
Set uiCommandButton1 = _
ActiveSheet.OLEObjects.Add("Forms.CommandButton.1")
With uiCommandButton1
.Object.Caption = "Show Form"
.Left = 71
.Top = 82
.Width = 60
.Height = 30
End With

Insert_uiCommandButton1_click_sub


End Sub

Sub Insert_uiCommandButton1_click_sub()
Dim sCode As String, sName As String, lNextLine As Long
sCode = "sub CommandButton1_click()" & vbCrLf
sCode = sCode & "UserForm2.Show" & vbCrLf
sCode = sCode & "End Sub" & vbCrLf

sName = ActiveSheet.CodeName

With ActiveWorkbook.VBProject. _
VBComponents(sName).CodeModule
lNextLine = .CountOfLines + 1
.InsertLines lNextLine, sCode
End With
End Sub
 
D

Dave Peterson

Try adding the optionbutton to the frame--not the form:

Set uiOptionButton1 = _
uiForm1.Designer.Controls.Add("Forms.OptionButton.1")

Becomes

Set uiOptionButton1 = _
uiFrame1.Controls.Add("Forms.OptionButton.1")
 
G

Guest

That solved it!

Thanks.

Dave Peterson said:
Try adding the optionbutton to the frame--not the form:

Set uiOptionButton1 = _
uiForm1.Designer.Controls.Add("Forms.OptionButton.1")

Becomes

Set uiOptionButton1 = _
uiFrame1.Controls.Add("Forms.OptionButton.1")
 

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