Jonnyoforem
New Member
- Joined
- May 22, 2015
- Messages
- 32
I'm trying to create a macro that will increase the height of a pre-existing user form, then add a textbox. I want this done at design-time so it will be permanent after running. I can't do it graphically because other users will be deciding when these text boxes need to be added. Here's the code I have so far.
The existing user form is called test and when I debug my code I get an error on the following line
The error is the following: Run-time error '-2147319767 (80028029)': Invalid forward reference, or reference to uncompiled type.
Thanks in advance for any help. And if I could also get an explanation as to why my code is failing that'd be great. I'd really like to tame the VBA beast.
Code:
Sub Practice()
Dim hght As Single
Dim NameUserForm As String
Dim MyUserForm As Object
Dim NewTextBox As MSForms.TextBox
'Name of userform
NameUserForm = "test"
Set MyUserForm = ThisWorkbook.VBProject _
.VBComponents(NameUserForm)
hght = MyUserForm.Properties("Height")
With MyUserForm
.Properties("Height") = hght + 25
End With
Set NewTextBox = MyUserForm.Controls.Add("Forms.TextBox.1")
With NewTextBox
.TextAlign = fmTextAlignCenter
.Width = 66
.Height = 18
.Left = 40
.Top = hght
End With
test.Show
End Sub
The existing user form is called test and when I debug my code I get an error on the following line
Code:
Set NewTextBox = MyUserForm.Designer.Controls.Add("Forms.TextBox.1")
The error is the following: Run-time error '-2147319767 (80028029)': Invalid forward reference, or reference to uncompiled type.
Thanks in advance for any help. And if I could also get an explanation as to why my code is failing that'd be great. I'd really like to tame the VBA beast.