Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
additem to listbox built on the fly
Sub try1()
Dim TempForm Dim NewListBox As MSForms.ListBox Set TempForm = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_M SForm) TempForm.Properties("width") = 150 Set NewListBox = TempForm.Designer.Controls.Add("forms.listbox.1", "Listbox1") With NewListBox .Height = 80 .Left = 20 .Top = 30 End With With TempForm.CodeModule X = .CountOfLines .InsertLines X + 1, "Sub Userform_Initialize()" .InsertLines X + 2, " Listbox1.Additem ""Trevor""" .InsertLines X + 3, " ListBox1.Additem ""Fred""" .InsertLines X + 4, "End Sub" End With VBA.UserForms.Add(TempForm.Name).Show End Sub Additem happens at runtime - so your form needs to exist to additem - i.e. additem is a method, not a property. Regards, Tom Ogilvy "trevor" wrote in message ... Hi, I'm trying to construct a form on the fly with a listbox. I can make the form and listbox appear but can't get the additem method to populate the listbox. The code I'm playing with follows. What am I missing? Thanks for any thoughts. Trevor Sub try1() Dim TempForm Dim NewListBox As MSForms.ListBox Set TempForm = ThisWorkbook.VBProject.VBComponents.Add (vbext_ct_MSForm) TempForm.Properties("width") = 150 Set NewListBox = TempForm.Designer.Controls.Add ("forms.listbox.1") With NewListBox .Height = 80 .Left = 20 .Top = 30 .AddItem "Trevor" .AddItem "Fred" End With VBA.UserForms.Add(TempForm.Name).Show End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
additem to listbox built on the fly
Many thanks Tom
-----Original Message----- Sub try1() Dim TempForm Dim NewListBox As MSForms.ListBox Set TempForm = ThisWorkbook.VBProject.VBComponents.Add (vbext_ct_MSForm) TempForm.Properties("width") = 150 Set NewListBox = TempForm.Designer.Controls.Add ("forms.listbox.1", "Listbox1") With NewListBox .Height = 80 .Left = 20 .Top = 30 End With With TempForm.CodeModule X = .CountOfLines .InsertLines X + 1, "Sub Userform_Initialize()" .InsertLines X + 2, " Listbox1.Additem ""Trevor""" .InsertLines X + 3, " ListBox1.Additem ""Fred""" .InsertLines X + 4, "End Sub" End With VBA.UserForms.Add(TempForm.Name).Show End Sub Additem happens at runtime - so your form needs to exist to additem - i.e. additem is a method, not a property. Regards, Tom Ogilvy "trevor" wrote in message ... Hi, I'm trying to construct a form on the fly with a listbox. I can make the form and listbox appear but can't get the additem method to populate the listbox. The code I'm playing with follows. What am I missing? Thanks for any thoughts. Trevor Sub try1() Dim TempForm Dim NewListBox As MSForms.ListBox Set TempForm = ThisWorkbook.VBProject.VBComponents.Add (vbext_ct_MSForm) TempForm.Properties("width") = 150 Set NewListBox = TempForm.Designer.Controls.Add ("forms.listbox.1") With NewListBox .Height = 80 .Left = 20 .Top = 30 .AddItem "Trevor" .AddItem "Fred" End With VBA.UserForms.Add(TempForm.Name).Show End Sub . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
ComboBox AddItem code to reference cells in a Range | Excel Discussion (Misc queries) | |||
listbox B conditional of input in Listbox A | Excel Discussion (Misc queries) | |||
Real quick: AddItem with combo boxes? | New Users to Excel | |||
additem to combobox with an array | Excel Discussion (Misc queries) | |||
Help with: ListBox1.AddItem (ws.Name) | Excel Worksheet Functions |