![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Winnipeg, Manitoba, CANADA
Posts: 130
|
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
__________________
Thanx. |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Try this code below. I got rid of some things. To add the option button to the frame, you use this command, "Set NewOptionButton = SetupFile.Frame.Controls.Add("forms.OptionButton.1")" This should work for you.
Kind regards, Al Function AddOptionButton(OpArray, Default, FrameTitle) Dim NewOptionButton, frame As control Dim i, TopPos As Integer Dim MaxWidth As Long TopPos = 10 Set Frame = SetupFile.Controls.Add("forms.frame.1") With Frame .Caption = FrameTitle .Enabled = True End With TopPos = 4 MaxWidth = 0 For i = LBound(OpArray) To UBound(OpArray) Set NewOptionButton = SetupFile.Frame.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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|