Hi,
I can't seem to get a textbox to programmatically add to a user form with the "AddTextBox" command. I'm unaware of another command which I could use to add a textbox. Also does anyone know of a way to autosize a form?
The code gets a compile error at the bolded section.
I can't seem to get a textbox to programmatically add to a user form with the "AddTextBox" command. I'm unaware of another command which I could use to add a textbox. Also does anyone know of a way to autosize a form?
The code gets a compile error at the bolded section.
Code:
Private Sub UserForm_Initialize()
'Stores selected System in TextBox1
TextBox1.Value = Sheets(2).Range("A1").Value
'Start Stores all Sub-Systems in auto-created textboxes
Dim tNewObject As TextBox
'Sets WidthVar
TempCount = 2
WidthVar = 0
While Worksheets(2).Cells(2, TempCount).Value <> ""
TempCount = TempCount + 4
WidthVar = WidthVar + 1
Wend
'Inputs textboxes
TempCount = 2
While Worksheets(2).Cells(2, TempCount).Value <> ""
'Sets position and size variables
PosW = 12.75
PosH = 23.25
PosL = (Summary1.Width / WidthVar)
PosTop = 66
'Adds Textboxes
With Summary1
[b]Set tNewObject = .AddTextbox(msoTextOrientationHorizontal, PosL, PosTop, PosW, PosH)[/b]
With tNewObject
.Value = "Worksheets(2).Cells(2, TempCount).Value"
End With
End With
Wend
'End Store all Sub-Systems in auto-created textboxes
'Auto-Sizes Form
With Summary1
.AutoSize = True
End With
End Sub