PDA

View Full Version : Solved: Form run time



joaquinfb
07-18-2012, 03:19 AM
Hi.

I’m working on form run time. The code is:


Sub Test()
Dim Frm As Object
Dim Frame As MSForms.Frame
Dim OptionB As MSForms.OptionButton


Set Frm = ThisWorkbook.VBProject.VBComponents.Add(3)

Set Frame = Frm.designer.Controls.Add("Forms.frame.1")
With Frame
.Name = "Frame1"
.Caption = "Frame1"
.Top = 5
.Left = 5
.Width = 75
.Height = 40
End With

Set OptionB = Frm.designer.Controls.Add("Forms.optionbutton.1")

With OptionB
.Name = "OButton1"
.Caption = "Female"
.Top = 15
.Left = 80
.Width = 60
.Height = 16
End With

Set OptionB = Frm.designer.Controls.Add("Forms.optionbutton.1")

With OptionB
.Name = "OButton2"
.Caption = "Male"
.Top = 15
.Left = 140
.Width = 60
.Height = 16
End With

VBA.UserForms.Add(Frm.Name).Show
ThisWorkbook.VBProject.VBComponents.Remove Frm


End Sub

I need to group optinbuttons into the frame.

How would I go about doing this?
thank.

mohanvijay
07-19-2012, 12:31 AM
Try this


Set OptionB = Frame.Controls.Add("Forms.optionbutton.1")

mikerickson
07-19-2012, 01:27 AM
I noticed that the option buttons are positioned outside the visible region of the frame.

joaquinfb
07-19-2012, 09:01 AM
Easy solution, but impossible for me without your help. thank you very much mohanvijay

I made ​​2 +2 = 5, again 2 +2 = 5 ... infinitely often



The final code to the correct position of the option buttom, is the following.

Sub Test()
Dim Frm As Object
Dim Frame As MSForms.Frame
Dim OptionB As MSForms.OptionButton


Set Frm = ThisWorkbook.VBProject.VBComponents.Add(3)

Set Frame = Frm.designer.Controls.Add("Forms.frame.1")
With Frame
.Name = "Frame1"
.Caption = "Frame1"
.Top = 5
.Left = 5
.Width = 75
.Height = 60
End With

'Set OptionB = Frm.designer.Controls.Add("Forms.optionbutton.1")
Set OptionB = Frame.Controls.Add("Forms.optionbutton.1")

With OptionB
.Name = "OButton1"
.Caption = "Female"
.Top = 15
.Left = 1
.Width = 60
.Height = 16
End With

'Set OptionB = Frm.designer.Controls.Add("Forms.optionbutton.1")
Set OptionB = Frame.Controls.Add("Forms.optionbutton.1")

With OptionB
.Name = "OButton2"
.Caption = "Male"
.Top = 30
.Left = 1
.Width = 60
.Height = 16
End With

VBA.UserForms.Add(Frm.Name).Show
ThisWorkbook.VBProject.VBComponents.Remove Frm

End Sub