Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default 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?
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tab Naming michelle Excel Worksheet Functions 0 October 12th 06 10:19 PM
Saving MSForm.Control (s) created at Runtime? Post Tenebras Lux Excel Programming 1 August 16th 06 07:31 AM
Creating an MSForm based on a table Quentin[_3_] Excel Programming 0 June 9th 06 07:48 PM
MSForm 1 - Initial placement of form Tim Coddington Excel Programming 2 October 1st 04 03:05 PM
MSForm 2 - Creating labels and text boxes at run time Tim Coddington Excel Programming 2 October 1st 04 03:03 PM


All times are GMT +1. The time now is 02:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"