Log in

View Full Version : ListBox Selection



stevebrugel
12-21-2011, 03:33 PM
I am trying to help user see what selection they have made in a Listbox by highlighting their selection. However this has a negative effect by running the code as if the item were selected from the listbox. Does someone know of a way to highlight a selection without it running the code again.
The offending line I have is....
WdxUserform.lstDocAndHypLnks.Selected(j) = True, which sets off...
Private Sub lstDocAndHypLnks_Click()

Any thought are appreciated
Steve

Dave
12-27-2011, 09:26 AM
If you set the listindex value of the listbox to the desired selection I think it just highlights the selection. HTH. Dave

stevebrugel
12-28-2011, 10:02 PM
I tried this but it has the same effect, using similar code
Private Sub CommandButton1_Click()
ListBox1.ListIndex = 3
End Sub
will cause this to be activated:
Private Sub ListBox1_Click()
MsgBox Application.ActiveDocument.Name
End Sub
is there another way to highlight w/o causing the ListBox1_Click to activate?

stevebrugel
12-29-2011, 09:25 AM
I also found a way to change the Font color, which would work...except it changes All the text:eek:

macropod
12-31-2011, 11:41 PM
Hi Steve,

Here's one way:
Dim bCmd As Boolean

Private Sub CommandButton1_Click()
bCmd = True
ListBox1.ListIndex = 3
bCmd = False
End Sub

Private Sub ListBox1_Click()
If bCmd = False Then MsgBox ListBox1.Value
End Sub

Note: You'd probably want to initialize 'bCmd = False' when the form loads.