Good day all, a brain teser possibly...
I want to dynamically add optionboxes to a Frame on a userform. The optionboxes are tied to a defined range. There will be 3 sets of frames w/optionboxes on the form. So if the Range is modified the correct amount of optionboxes would appear. Below is my function that doesn't work but it's a start....
Function AddOptionButton(OpArray, Default, FrameTitle)
Dim NewOptionButton As MSForms.optionbutton
Dim Frame As MSForms.Frame
Dim i As Integer, TopPos As Integer
Dim MaxWidth As Long
TopPos = 10
Set Frame = SetupFile.Controls.Add("forms.frame.1")
With Frame
.Caption = FrameTitle
.Enabled = True
.Controls.Add ("forms.OptionButton.1") '?? = .Caption = OpArray(i)
End With
' This works but how do I add it to the frame?
' Add the OptionButtons
TopPos = 4
MaxWidth = 0 'Stores width of widest OptionButton
For i = LBound(OpArray) To UBound(OpArray)
Set NewOptionButton = SetupFile.Controls.Add("forms.OptionButton.1")
With NewOptionButton
.Width = 800
.Caption = OpArray(i)
.Height = 15
.Left = 8
.Top = TopPos
.Tag = i
.AutoSize = True
If Default = i Then .Value = True
If .Width > MaxWidth Then MaxWidth = .Width
End With
TopPos = TopPos + 15
Next i
End Function
I want to dynamically add optionboxes to a Frame on a userform. The optionboxes are tied to a defined range. There will be 3 sets of frames w/optionboxes on the form. So if the Range is modified the correct amount of optionboxes would appear. Below is my function that doesn't work but it's a start....
Function AddOptionButton(OpArray, Default, FrameTitle)
Dim NewOptionButton As MSForms.optionbutton
Dim Frame As MSForms.Frame
Dim i As Integer, TopPos As Integer
Dim MaxWidth As Long
TopPos = 10
Set Frame = SetupFile.Controls.Add("forms.frame.1")
With Frame
.Caption = FrameTitle
.Enabled = True
.Controls.Add ("forms.OptionButton.1") '?? = .Caption = OpArray(i)
End With
' This works but how do I add it to the frame?
' Add the OptionButtons
TopPos = 4
MaxWidth = 0 'Stores width of widest OptionButton
For i = LBound(OpArray) To UBound(OpArray)
Set NewOptionButton = SetupFile.Controls.Add("forms.OptionButton.1")
With NewOptionButton
.Width = 800
.Caption = OpArray(i)
.Height = 15
.Left = 8
.Top = TopPos
.Tag = i
.AutoSize = True
If Default = i Then .Value = True
If .Width > MaxWidth Then MaxWidth = .Width
End With
TopPos = TopPos + 15
Next i
End Function