ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Double click item in Listbox to select item and close Listbox (https://www.excelbanter.com/excel-programming/393623-double-click-item-listbox-select-item-close-listbox.html)

GusEvans

Double click item in Listbox to select item and close Listbox
 
Have a large complicated VBA Project in which the first item after it starts
is displaying a Listbox with 30 items (single select). Now the user must
select the item and click the OK Button (it works). But from a windows GUI
viewpoint they should be able to just double click the desired item and have
it work the same as select and click OK. I have looked all through the
Properties Window but see nothing to make it work. Just want to make it work
like a real Windows App.
XP Pro - Excel 2003

Any help (even if can't be done) would be appreciated.
--
Gus Evans

Rick Rothstein \(MVP - VB\)

Double click item in Listbox to select item and close Listbox
 
Have a large complicated VBA Project in which the first item after it
starts
is displaying a Listbox with 30 items (single select). Now the user must
select the item and click the OK Button (it works). But from a windows
GUI
viewpoint they should be able to just double click the desired item and
have
it work the same as select and click OK. I have looked all through the
Properties Window but see nothing to make it work. Just want to make it
work
like a real Windows App.
XP Pro - Excel 2003


Assuming your OK button is an ActiveX control named CommandButton1 for this
example (user your actual control's name, of course), just put this one line
in the ListBox's DoubleClick event...

CommandButton1_Click

and double clicking an item will do the same as selecting an item and
clicking the CommandButton.


Rick


GusEvans

Double click item in Listbox to select item and close Listbox
 
Great - worked like a charm!
--
Gus Evans


"Rick Rothstein (MVP - VB)" wrote:

Have a large complicated VBA Project in which the first item after it
starts
is displaying a Listbox with 30 items (single select). Now the user must
select the item and click the OK Button (it works). But from a windows
GUI
viewpoint they should be able to just double click the desired item and
have
it work the same as select and click OK. I have looked all through the
Properties Window but see nothing to make it work. Just want to make it
work
like a real Windows App.
XP Pro - Excel 2003


Assuming your OK button is an ActiveX control named CommandButton1 for this
example (user your actual control's name, of course), just put this one line
in the ListBox's DoubleClick event...

CommandButton1_Click

and double clicking an item will do the same as selecting an item and
clicking the CommandButton.


Rick



Incidental

Double click item in Listbox to select item and close Listbox
 
Hi Gus

You could do it using code like that listed below

Option Explicit
Dim LstSelection As String

Private Sub CommandButton1_Click()
Call DoYourThingHere
End Sub

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Call DoYourThingHere
End Sub

Sub DoYourThingHere()
LstSelection = ListBox1.Value
MsgBox LstSelection
ListBox1.Visible = False
End Sub

hope this helps

S



All times are GMT +1. The time now is 08:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com