O
OssieMac
Will very much appreciate it if someone can tell my what I have got wrong in
the example code. I have searched unsuccessfully for the answer.
See comment in code where following error is returned.
Runtime error 438 - Object doesn't support this property or method.
I want to add an ActiveX ListBox with MultiSelect to a Worksheet and then
populate it with AddItem.
Private Sub CommandButton2_Click()
Dim lListBox As Long
Dim tListBox As Long
Dim hListBox As Long
Dim wListBox As Long
Dim lstBox As OLEObject
With ActiveSheet
lListBox = .Cells(2, 2).Left
tListBox = .Cells(2, 2).Top
wListBox = 100
hListBox = 150
Set lstBox = .OLEObjects.Add _
(ClassType:="Forms.ListBox.1", _
Link:=False, _
DisplayAsIcon:=False, _
Left:=lListBox, _
Top:=tListBox, _
Width:=wListBox, _
Height:=hListBox)
'Following 2 line work
lstBox.Name = "MyList"
MsgBox lstBox.Name
'****************************************
'Following lines return the error
lstBox.MultiSelect = fmMultiSelectMulti
lstBox.AddItem "Test"
End With
End Sub
the example code. I have searched unsuccessfully for the answer.
See comment in code where following error is returned.
Runtime error 438 - Object doesn't support this property or method.
I want to add an ActiveX ListBox with MultiSelect to a Worksheet and then
populate it with AddItem.
Private Sub CommandButton2_Click()
Dim lListBox As Long
Dim tListBox As Long
Dim hListBox As Long
Dim wListBox As Long
Dim lstBox As OLEObject
With ActiveSheet
lListBox = .Cells(2, 2).Left
tListBox = .Cells(2, 2).Top
wListBox = 100
hListBox = 150
Set lstBox = .OLEObjects.Add _
(ClassType:="Forms.ListBox.1", _
Link:=False, _
DisplayAsIcon:=False, _
Left:=lListBox, _
Top:=tListBox, _
Width:=wListBox, _
Height:=hListBox)
'Following 2 line work
lstBox.Name = "MyList"
MsgBox lstBox.Name
'****************************************
'Following lines return the error
lstBox.MultiSelect = fmMultiSelectMulti
lstBox.AddItem "Test"
End With
End Sub