Hi UpSkill,
Welcome to board !!
This worked for me. (Using Win 8 64 bit, Excel 2010)
Code:Option Explicit Sub Add_Control() '//*************Make sure access to the VBProject is allowed*********************** ' Declare variables. Dim NewForm As Object Dim lb As Object Dim c As Object Dim r As Long ' Create a new UserForm. You can use this new VBComponent object ' to manipulate the UserForm. Set NewForm = Application.VBE.ActiveVBProject.VBComponents.Add(vbext_ct_MSForm) With NewForm .Properties("Caption") = "New Form" .Properties("Width") = 200 .Properties("Height") = 350 End With ' Delete all controls, if any For Each c In NewForm.Designer.Controls NewForm.Designer.Remove c.Name Next c 'Add Labels For r = 1 To 10 Set lb = NewForm.Designer.Controls.Add("Forms.Label.1") With lb .Width = 50 .Height = 25 .Left = 10 .Top = (r * .Height) + 35 .Caption = Worksheets(3).Cells(r, 1) .Tag = "ItemNo " & r .Name = "lbItemNo" & r End With Next VBA.UserForms.Add(NewForm.Name).Show End Sub




Reply With Quote
Bookmarks