don’t see the Controls on the Forms generated at runtime

A

Abhishake Saravgi

I have developed a VB6.0 exe which generated Excel templates. Each excel
template have two user forms. I want to add controls like List box, Combo
box, Command Box and Text Boxes in these user forms through VB6.0 code. Now
when the End User uses this template he can see these controls.
I have also added the controls at runtime through VB 6.0 and save the Excel
template. When I open the template I don’t see the Controls on the Forms
Please any one can guide me how to do this from VB 6.0 and would we a great
help if some provide me with the code
 
P

Peter T

Controls added to Userforms at runtime do not persist. If you want to
programmatically create your form and add controls that can be saved with
the workbook, append your reference to the form with .Designer, eg

Sub test()
Dim wb As Excel.Workbook
Dim vbCmp As Object 'VBIDE.VBComponent with ref to VBA extensibility
Dim ctl As Object

Set wb = Application.Workbooks.Add

Set vbCmp = wb.VBProject.VBComponents.Add(3) ' vbext_ct_MSForm
With vbCmp.Designer
Set ctl = .Controls.Add("Forms.CommandButton.1")
With ctl
.Left = 20
.Top = 10
.Caption = "Hello"
End With
End With

End Sub

Above of course is Excel/VBA, change 'Application' to your VB6 ref to Excel,
eg xlApp. Presumably you will want to add code to the form as well. Unless
you need to redesign the form according to latest needs, I would have
thought easier to save a pre-made form to file, distribute the .frm & .frx
and simply import the .frm. to the vbProject

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top