K
Keb
Hello -
I'm using Excel 2000 VBA to programmatically create a userform
containing a listbox. I can watch the userform as it is created and
filled (via the debugger), but as soon as the show line executes, the
listbox entries disappear - other items, such as checkbox labels &
buttons appear fine.
Can someone tell me how to solve this problem, and more importantly,
why it is occuring?
I have one other question also: A width property can be set for an
item such as a command button however that property is neither seen in
the complete_word dropdown list nor in the object browser for the item
- it can be seen in the Properties Window, however. Why ??
Thanks in advance, (Please post any replies, as I cannot access the
email acct easily).
Keb
Here is a simplified version of my code:
Sub ShowListbox()
Dim TempForm
Dim NewListBox As MSForms.ListBox
Dim i As Integer
Application.VBE.MainWindow.Visible = False
'
' Create the userform
'
Set TempForm = ThisWorkbook.VBProject.VBComponents.Add(3)
TempForm.Properties("Width") = 100
'
' Add listbox & populate it.
'
Set NewListBox = TempForm.Designer.Controls.Add("forms.ListBox.1", , True)
For i = 1 To 10
NewListBox.AddItem "Item " & LTrim(Str(i))
Next
'
' Show the form.
'
VBA.UserForms.Add(TempForm.Name).Show
'
' Delete the form & clean up.
'
ThisWorkbook.VBProject.VBComponents.Remove VBComponent:=TempForm
Set TempForm = Nothing
Set NewListBox = Nothing
End Sub
I'm using Excel 2000 VBA to programmatically create a userform
containing a listbox. I can watch the userform as it is created and
filled (via the debugger), but as soon as the show line executes, the
listbox entries disappear - other items, such as checkbox labels &
buttons appear fine.
Can someone tell me how to solve this problem, and more importantly,
why it is occuring?
I have one other question also: A width property can be set for an
item such as a command button however that property is neither seen in
the complete_word dropdown list nor in the object browser for the item
- it can be seen in the Properties Window, however. Why ??
Thanks in advance, (Please post any replies, as I cannot access the
email acct easily).
Keb
Here is a simplified version of my code:
Sub ShowListbox()
Dim TempForm
Dim NewListBox As MSForms.ListBox
Dim i As Integer
Application.VBE.MainWindow.Visible = False
'
' Create the userform
'
Set TempForm = ThisWorkbook.VBProject.VBComponents.Add(3)
TempForm.Properties("Width") = 100
'
' Add listbox & populate it.
'
Set NewListBox = TempForm.Designer.Controls.Add("forms.ListBox.1", , True)
For i = 1 To 10
NewListBox.AddItem "Item " & LTrim(Str(i))
Next
'
' Show the form.
'
VBA.UserForms.Add(TempForm.Name).Show
'
' Delete the form & clean up.
'
ThisWorkbook.VBProject.VBComponents.Remove VBComponent:=TempForm
Set TempForm = Nothing
Set NewListBox = Nothing
End Sub