Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
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
ComboBox AddItem code to reference cells in a Range HBC_MT Excel Discussion (Misc queries) 0 February 26th 09 04:05 PM
listbox B conditional of input in Listbox A Kim K Excel Discussion (Misc queries) 1 October 31st 06 08:27 PM
Real quick: AddItem with combo boxes? AVERAGE(user) New Users to Excel 3 October 29th 05 10:13 AM
additem to combobox with an array jocke Excel Discussion (Misc queries) 2 September 29th 05 07:56 PM
Help with: ListBox1.AddItem (ws.Name) Ron de Bruin Excel Worksheet Functions 0 May 18th 05 07:02 PM


All times are GMT +1. The time now is 10:29 AM.

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

About Us

"It's about Microsoft Excel"