![]() |
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 |
About Naming MSForm in VBE.
On Jan 2, 9:24 am, fujing1003 wrote:
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 Somebody replays as follows: '------------------------------------------------------------------------------------------------------------------- Once you run your code, VBE constructor has allocated used userform names in cache during a VBE session. If you want to create a new userform (eventhough it is deleted physically from the VBcomponents collection) using a previously used name in the same VBE session, you'll see this error. '------------------------------------------------------------------------------------------------------------------- It's reasonable,but how to clear userform in this vbe session? |
About Naming MSForm in VBE.
I get the same problem even if doing all manually. However, some while ago I
noticed if you drag form-name from another wb all seems to work (assuming of course form-name no longer exists in the main wb). Based on same idea try the following: Sub AddAndRenameVBComponent2() Dim oProjForm As VBComponent Dim oProj As VBProject Dim wb As Workbook Set wb = Workbooks.Add 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 = wb.VBProject.VBComponents.Add(vbext_ct_MSForm) oProjForm.Name = sFormName GoSub KillForm oProjForm.Export "c:\temp\FormTest.frm" wb.Close False ' can't 'step through this line, run/F5 Set oProjForm = oProj.VBComponents.Import("c:\temp\FormTest.frm") GoSub KillForm Exit Sub KillForm: On Error Resume Next Kill "c:\temp\FormTest.frm" Kill "c:\temp\FormTest.frx" On Error GoTo 0 Return End Sub Regards, Peter T "fujing1003" wrote in message ... On Jan 2, 9:24 am, fujing1003 wrote: 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 Somebody replays as follows: '--------------------------------------------------------------------------- ---------------------------------------- Once you run your code, VBE constructor has allocated used userform names in cache during a VBE session. If you want to create a new userform (eventhough it is deleted physically from the VBcomponents collection) using a previously used name in the same VBE session, you'll see this error. '--------------------------------------------------------------------------- ---------------------------------------- It's reasonable,but how to clear userform in this vbe session? |
All times are GMT +1. The time now is 09:03 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com