I'd like to get the index of the selected item in a ListBox in VBA.
In real VB I do it with the following code:
Private Declare Function SendMessage Lib "user32" Alias
As Long, lParam As Any) As Long
Private Sub UserForm_Initialize()
Dim Counter As Long
For Counter = 1 To 20
ListBox1.AddItem "MyItem " & Counter
CommandButton1.Caption = "Index of selected Item"
Private Sub CommandButton1_Click()
MsgBox (SendMessage(ListBox1.hWnd, &H19F, 0, 0))
But how can I do it in VBA (e.g. Excel)?