--------------------------------
Solution 2.
You could also just make the proceedure a Sub, declare a module level variable, and write it like this:
Public mp_vSelectedList As Variant
Private Sub GetSelectedListItems()
Dim I As Integer
Dim iMaxSelected As Integer
If List1.ListCount > 0 Then
ReDim mp_vSelectedList(List1.ListCount - 1)
For I = 0 To List1.ListCount - 1
If List1.Selected(I) Then mp_vSelectedList(iMaxSelected) = List1.List(I)
iMaxSelected = iMaxSelected + 1
End If
Next I
End If
If iMaxSelected Then
ReDim Preserve mp_vSelectedList(iMaxSelected - 1)
Else
mp_vSelectedList = Empty
End If
End Sub
Private Sub test()
Dim vItem As Variant
Call GetSelectedListItems
If Not IsEmpty(mp_vSelectedList) ThenFor Each vItem In mp_vSelectedList
Debug.Print vItem
Next vItem
End If
End Sub
--------------------------------
Solution 3.
combining Answer #3 with my answer you could have the function return a string, and in the function, if the item was selected, add the item to a string along with a pipe, as opposed to using an array:
If List1.Selected(I) Then
sSelectedList = List1.List(I) & "|"
End If
Then loop through the items like this:
Private Sub test()
Dim vSelectedItems As Variant
Dim vItem As Variant
vSelectedItems = GetSelectedListItems()
if Len(vSelectedItems)>0 then
vSelectedItems=Split(vSelectedItems,"|")
Else
vSelectedItems=Empty
End IF
If IsArray(vSelectedItems) Then
For Each vItem In vSelectedItems
Debug.Print vItem
Next vItem
End If
End Sub