S
Stefan Mueller
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
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam
As Long, lParam As Any) As Long
Private Sub UserForm_Initialize()
Dim Counter As Long
ListBox1.Clear
For Counter = 1 To 20
ListBox1.AddItem "MyItem " & Counter
Next
CommandButton1.Caption = "Index of selected Item"
End Sub
Private Sub CommandButton1_Click()
MsgBox (SendMessage(ListBox1.hWnd, &H19F, 0, 0))
End Sub
But how can I do it in VBA (e.g. Excel)?
In real VB I do it with the following code:
Private Declare Function SendMessage Lib "user32" Alias
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam
As Long, lParam As Any) As Long
Private Sub UserForm_Initialize()
Dim Counter As Long
ListBox1.Clear
For Counter = 1 To 20
ListBox1.AddItem "MyItem " & Counter
Next
CommandButton1.Caption = "Index of selected Item"
End Sub
Private Sub CommandButton1_Click()
MsgBox (SendMessage(ListBox1.hWnd, &H19F, 0, 0))
End Sub
But how can I do it in VBA (e.g. Excel)?