Hi Shawn,
Yes you can. This code moves the selected item in a listbox one position up:
----------------------------------------
Private Sub CommandButton1_Click()
Dim lNewIndex As Long
'Check if selected item is
'not the first in list
If ListBox1.ListIndex <> 0 Then
'Get new position:
'Current listidex - 1
lNewIndex = ListBox1.ListIndex - 1
With ListBox1
'Add new item on new position
.AddItem , lNewIndex
'add text of selected item at new position
.List(lNewIndex) = ListBox1.List(ListBox1.ListIndex)
'Remove old item
.RemoveItem (ListBox1.ListIndex)
'Select new position
.ListIndex = lNewIndex
End With
Else
MsgBox "First item, can't move up"
End If
End Sub
----------------------------------------
Hope this helps,
regards,
Astrid
So that all can benefit from the discussion, please post all follow-ups to the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/
Quote:
> Is there a way to move items in a listbox?
> for example:
> there are 5 items in a listbox
> can i get the fourth item to swap indexes with the fifth?
> thanks
> Shawn