Function GetSelectedItems(ByRef lstBox As ListBox, Optional ByRef asRet) As Integer
'lstBox listbox de recherche
'asRet tableau string retournant les items
'retour nombre d'items trouvés
Dim i As Integer
Dim j As Integer
j = -1
If Not lstBox Is Nothing Then
If IsMissing(asRet) Then ReDim asRet(0) As String
For i = 0 To lstBox.ListCount - 1
If lstBox.Selected(i) Then
j = j + 1
ReDim Preserve asRet(j)
asRet(j) = lstBox.List(i)
End If
Next i
End If
GetSelectedItems = j + 1
End Function
'EXEMPLE 1 : COMPTER
MsgBox "il y a " & CStr(GetSelectedItems(List1)) & " item(s) sélectionné(s)"
'EXEMPLE 2 : LISTER
Dim items() As String
If GetSelectedItems(List1, items) > 0 Then
MsgBox "Les items sélectionnés sont :" & vbCrLf & _
"- " & Join(items, vbCrLf & "- ")
Else
MsgBox "aucun item sélectionné"
End If