I am trying to automatize an e-mail, but I am having a problem when I try to send lines from listbox; I have tried a few different ways none that were even close to working. In
If you have allowed the MultiSelect property for the listbox to True, try this...
Dim listboxarr()
Dim i As Long, j As Long
'Assuming the name of your ListBox is ListBox1. If not, change it in the following code.
With Me.ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
j = j + 1
ReDim Preserve listboxarr(1 To j)
listboxarr(j) = .List(i)
End If
Next i
End With
Edited Code:
Dim listboxarr()
Dim i As Long, j As Long
Dim found As Boolean
'Assuming the name of your ListBox is ListBox1. If not, change it in the following code.
With Me.ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
found = True
j = j + 1
ReDim Preserve listboxarr(1 To j)
listboxarr(j) = .List(i)
End If
Next i
End With
And then you can use it like below...
.body = IIf(found, Join(listboxarr, ", "), "No item selected")