Patriot2879
Well-known Member
- Joined
- Feb 1, 2018
- Messages
- 1,259
- Office Version
- 2010
- Platform
- Windows
Hi good afternoon and happy new year to you all. i hope you can help me with the code below please, i have a listbox2 which has data in, when i select a row in the listbox and click the commandbutton i want the values in that row to be populated in the body of the email, and have the email open. can you help please.
VBA Code:
Private Sub CommandButton11_Click()
Dim oApp, oMail As Object, _
tWB, cWB As Workbook, _
FileName, FilePath As String, _
MailBody As String, MailSubject As String, Disclaimer As String
Dim first As Boolean
first = True
Application.ScreenUpdating = False
Set oApp = CreateObject("Outlook.Application")
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
If first = False Then
mailid = mailid & ";" & ListBox1.ListIndex(i)
Else
mailid = ListBox1.ListIndex(i)
first = False
End If
End If
Next
MailBody = YourMessageBodyStringVariable
MailSubject = YourMessageSubjectStringVariable
If MailBody = vbNullString Then
Beep
MsgBox "Must Provide Body Text"
GoTo quitpoint
End If
If MailSubject = vbNullString Then
Beep
MsgBox "Must Provide Subject Line Text"
GoTo quitpoint
End If
Set oMail = oApp.CreateItem(0)
With oMail
.to = ""
.Subject = ""
.Body = MailBody & Chr(10) & Chr(10) & Disclaimer
.Send
End With
quitpoint:
Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
End Sub