Prgrammatically added OLE Listbox, now cannot select from it
"happyheth" wrote in message
Hi,
I have a macro that creates an OLEobject list box and popualtes it. Once
the macro ends, I cannot select from the listbox unless I switch into
design mode and back out.
I have a single activex button that runs this code.
Private Sub CommandButton1_Click()
Set lb1 = ActiveSheet.OLEObjects.Add(ClassType:="Forms.ListB ox.1", _
Link:=False, DisplayAsIcon:=False, Left:=10, Top:=currX,
Width:=560, Height:=60)
With lb1.Object
.AddItem
.ColumnCount = 4
.ColumnWidths = "100;150;150;150"
.List(0, 0) = " "
.List(0, 1) = "Database"
.List(0, 2) = "Server"
.List(0, 3) = "Version"
End With
End Sub
Once complete, I what to select the row displayed but cannot. Help?
Try toggling design mode with code, eg
Dim cb As CommandBarButton
Set cb = Application.VBE.CommandBars.FindControl(ID:=212)
cb.Execute
cb.Execute
Can also toggle the ribbon button with
CommandBars.ExecuteMso "DesignMode"
though it can be a bit fiddly to avoid the code terminating on that
particular call
Regards,
Peter T
|