I believe I do just what you desire. I simply set the ListIndex
and it works for me. I do it for a serial port set up UserForm and if
the cancel button is clicked, the previous values are "re-highlighted"
in the list box.
The code you see here is the entire sub code when a cancel button is
clicked.
The first two lines of code below reset two list boxes back to the
"before change" values and highlights them. If the list has been
scrolled away from those values so that the original value is no
longer visible, they scroll back so they are shown. The values that
were loaded into the list boxes when the UserForm is initialized are
the values in those same Sheet4 Ranges, therefore any changes are aborted.
I do not know, however, if the repaint is required.
This is on Excel 97.
RE the Wait:
I also show a short "changes accepted" or "chenges ignored" text
for that Wait period.
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Public Sub DontChange()
'Restore Port
PortVFO1.ListIndex = Sheet4.Range("ComPortVFO_1") - 1
'Restore Baud
BaudVFO1.ListIndex = Sheet4.Range("Baud_1") - 1
Me.ChangesCancel.Visible = True
Me.Repaint
Wait (100)
Me.ChangesCancel.Visible = False
End Sub