View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
fujing1003 fujing1003 is offline
external usenet poster
 
Posts: 11
Default About Naming MSForm in VBE.


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