I am trying to add files to a list box in the same way as they are added when files are attached to an email, in two columns but able to address each file uniquely. I am using A
Try mapping the indices of the items in the listBox to the files using a separate array/collection/dictionary. Then, when an item is selected, you can use the item's index to get the link
I just tried this below, works perfectly.
Userform Code:
Private d As Dictionary
Private Sub userform_initialize()
Set d = New Dictionary
'populate list box, and add items to dictionary
For i = 1 To 3
With ListBox1
d.Add .ListCount, "Link" & i
.AddItem 0
.List(.ListCount - 1) = "Hello World"
End With
Next
End Sub
'update label1's value based of listbox's selected item
Private Sub ListBox1_Change()
With ListBox1
If .ListIndex <> -1 Then
Label1.Caption = d.Item(.ListIndex)
End If
End With
End Sub
And the userform looked like this: (listbox named ListBox1, and label named Label1):
Example:
If you have problems using the dictionary object, you need to add a reference to "Microsoft Scripting Runtime". But really any collection-type can replace the dictionary in this case (an array/Collection)