ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   dont see the Controls on the Forms generated at runtime (https://www.excelbanter.com/excel-programming/406847-don%E2%80%99t-see-controls-forms-generated-runtime.html)

Abhishake Saravgi

dont see the Controls on the Forms generated at runtime
 
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 dont 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




Peter T

don't see the Controls on the Forms generated at runtime
 
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

"Abhishake Saravgi" wrote in
message ...
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







All times are GMT +1. The time now is 07:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com