Jonnyoforem
New Member
- Joined
- May 22, 2015
- Messages
- 32
I have a function that creates a user form with certain specifications that I want. I want the user to specify how many textboxes are created when they run the function (That's what OpArray represents). The only problem is when the textboxes are created, they're supposed to be a certain size but nothing I do sizes them properly. I don't get any errors, I just get textboxes with a width of 12.5 instead of the 66 that I specify. Here's the pertinent part of my code.
I'm pretty new at manipulating VBA components. Any help would be appreciated. This is seriously just baffling me.
Code:
Function GetOption1(OpArray)
Dim TempForm As Object
Dim NewTextBox As MSForms.TextBox
Dim i As Integer, TopPos As Integer
'Hide VBE window to prevent screen flashing
Application.VBE.MainWindow.Visible = False
'Create the UserForm
Set TempForm = _
ThisWorkbook.VBProject.VBComponents.Add(3)
TempForm.Properties("Width") = 800
'Add the TextBoxes
TopPos = 4
'MaxWidth = 0 'Stores width of widest TextBox
For i = LBound(OpArray) To UBound(OpArray)
Set NewTextBox = TempForm.Designer.Controls. _
Add("Forms.TextBox.1")
With NewTextBox
.Width = 66
'.Value = OpArray(i)
.Height = 100
.Left = 8
.Top = TopPos
.Tag = i
.AutoSize = True
If Default = i Then .Value = True
If .Width > MaxWidth _
Then MaxWidth = .Width
End With
TopPos = TopPos + 20
Next i
VBA.UserForms.Add(TempForm.Name).Show
End Function
I'm pretty new at manipulating VBA components. Any help would be appreciated. This is seriously just baffling me.