-
Solved: Form run time
Hi.
I’m working on form run time. The code is:
[vba]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
[/vba]
I need to group optinbuttons into the frame.
How would I go about doing this?
thank.
-
Try this
[vba]
Set OptionB = Frame.Controls.Add("Forms.optionbutton.1")
[/vba]
-
I noticed that the option buttons are positioned outside the visible region of the frame.
-
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.
[vba]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
[/vba]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules