I'm creating a Userform programmatically which is fine but then I want to replace it based upon a different Specification.
I delete the Userform first and then create a new Userform but when I come to name it using the name of the Userform that I have just deleted it gives me an error
on this line : .Name = strName
Run-time error 75
Could not find the specified object.
Do I have to clear the deleted Userform from memory or something?
I delete the Userform first and then create a new Userform but when I come to name it using the name of the Userform that I have just deleted it gives me an error
on this line : .Name = strName
Run-time error 75
Could not find the specified object.
Do I have to clear the deleted Userform from memory or something?
VBA Code:
Option Explicit
Private Sub subCreateuserform()
Dim MyUserForm As VBComponent
Dim strName As String
ActiveWorkbook.Save
Call subDeleteForm("frmMyForm")
strName = "frmMyForm"
Set MyUserForm = ActiveWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
With MyUserForm
.Properties("Height") = 377
.Properties("Width") = 260
.Name = strName
.Properties("Caption") = "My Form"
End With
End Sub
Public Sub subDeleteForm(strUserform As String)
Dim VBComps As VBIDE.VBComponents
Dim VBComp As VBIDE.VBComponent
Set VBComps = ActiveWorkbook.VBProject.VBComponents
On Error Resume Next
Set VBComp = VBComps(strUserform)
VBComps.Remove VBComp
On Error GoTo 0
Set VBComps = Nothing
End Sub