A UserForm can be created using code such as that below.
However, if an attempt is made to run this code a second time an error will be encountered:
Code:
Sub Add_Form2()
' Declare a variable to hold the UserForm.
Dim mynewform As Object
' Create a new UserForm. You can now use this new VBComponent object
' to manipulate the User Form.
Set mynewform = _
Application.VBE.ActiveVBProject.VBComponents.Add(vbext_ct_MSForm)
With mynewform
.Properties("Height") = 246
.Properties("Width") = 616
.Name = "HelloWord"
.Properties("Caption") = "This is a test"
End With
End Sub
The code hangs on the .Name = "HelloWord" line. Is there a means by which one can clear the object from memory or whatever so that this error is not encountered? I've tried to delete the forms, tried to unload the forms but nothing seems to work. It appears that it’s the naming of the form that's the problem. I could leave it as "UserForm1" but would like to know how this works anyway.Run-time error '75':
"Could not find the specified object."