F
fujing1003
The following code could only run correctly once after the workbook's
open. I could not understand why we couldn't name a form as the early
one we've deleted before. IF we change vbext_ct_MSForm to
vbext_ct_StdModule, all goes well.
What's the reason of it? Is it caused by form's designer object?
Thanks in advance.
Sub AddAndRenameVBComponent()
Dim oProjForm As VBComponent
Dim oProj As VBProject
Const sFormName As String = "FormTest"
Set oProj = ThisWorkbook.VBProject
On Error Resume Next
oProj.VBComponents.Remove oProj.VBComponents(sFormName)
On Error GoTo 0
Set oProjForm = oProj.VBComponents.Add(vbext_ct_MSForm)
With oProjForm
.Name = "Test"
End With
End Sub
open. I could not understand why we couldn't name a form as the early
one we've deleted before. IF we change vbext_ct_MSForm to
vbext_ct_StdModule, all goes well.
What's the reason of it? Is it caused by form's designer object?
Thanks in advance.
Sub AddAndRenameVBComponent()
Dim oProjForm As VBComponent
Dim oProj As VBProject
Const sFormName As String = "FormTest"
Set oProj = ThisWorkbook.VBProject
On Error Resume Next
oProj.VBComponents.Remove oProj.VBComponents(sFormName)
On Error GoTo 0
Set oProjForm = oProj.VBComponents.Add(vbext_ct_MSForm)
With oProjForm
.Name = "Test"
End With
End Sub