I would like to take the contents of a multi-selection listbox and put them into the body of an email message. I found the following code but it does not work for me:
My list box has 7 columns that I would like to grab the first 6 in the email body.
Any help is greatly appreciated!
Private Sub EEList_DblClick(Cancel As Integer)
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim ctl As Control
Dim str As String
Dim varItem As Variant
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set ctl = Me.EEList
For Each varItem In ctl.ItemsSelected
str = str & ctl.ItemData(varItem) & ", " & vbCrLf
Next varItem
str = Left$(str, Len(str) - 3)
str = str & ")"
With MailOutLook
.BodyFormat = olFormatRichText
.To = ""
.Subject = "Employee(s) to be Termed"
.HTMLBody = str & Chr(13) & Me.typetext & Chr(13)
.Display (True)
End With
'MsgBox MailOutLook.Body
Exit Function
email_error:
MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
Resume Error_out
Error_out:
End Sub
My list box has 7 columns that I would like to grab the first 6 in the email body.
Any help is greatly appreciated!
Private Sub EEList_DblClick(Cancel As Integer)
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim ctl As Control
Dim str As String
Dim varItem As Variant
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set ctl = Me.EEList
For Each varItem In ctl.ItemsSelected
str = str & ctl.ItemData(varItem) & ", " & vbCrLf
Next varItem
str = Left$(str, Len(str) - 3)
str = str & ")"
With MailOutLook
.BodyFormat = olFormatRichText
.To = ""
.Subject = "Employee(s) to be Termed"
.HTMLBody = str & Chr(13) & Me.typetext & Chr(13)
.Display (True)
End With
'MsgBox MailOutLook.Body
Exit Function
email_error:
MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
Resume Error_out
Error_out:
End Sub