takingiwhanau
New Member
- Joined
- Aug 30, 2011
- Messages
- 8
- Office Version
- 365
- Platform
- Windows
If I found code to send a single table from excel to outlook using HTML in the VBA Code. But I couldn't find code to sort the table to highlight each individual vendor and copy that table into the email body then move onto the next vendor till the last vendor is reached.
I have found the below code that will copy a filtered table and paste into the body of an email using HTML which is the end result I want for each different vendor. I can't figure out how to automate the macro to loop and filter the table to the next vendor in the table and then copy that lot of changed data to a new email.
Sub send_mass_email()
Dim i As Integer, cel As Range
Dim Name, Email, body, Subject, copy, Minesite, Workorder, str1, str2 As String
Dim OutApp As Object, OutMail As Object
Dim pop As Range
Set OutApp = CreateObject("Outlook.Application")
count_row = WorksheetFunction.CountA(Range("a1", Range("a1").End(xlDown)))
count_col = WorksheetFunction.CountA(Range("a1", Range("a1", "r1")))
Set pop = Sheets("Vendor Emails").Range(Cells(1, 5), Cells(count_row, count_col))
str1 = "<BODY style = font-size:12pt;font-family:Calibri>" & _
"Hello Team, <br><br> Can we please have an update on the purchase order/s below.<br>"
str2 = "<br>For further inforation please contact us below.<br>"
For Each cel In Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
Email = Split(cel, " ")(0) 'extract first name
Name = cel.Offset(, 2).Value
Subject = cel.Offset(, 4).Value
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = Email
.Subject = Subject & " " & Name & " PURCHASE ORDER UPDATES"
.display
.HTMLBody = str1 & RangetoHTML(pop) & str2 & .HTMLBody
'.Send
End With
If cel.Offset(1, 0).Value = cel.Offset(2, 0) Then
MsgBox "Email(s) Created!"
End
End If
If cel.Offset(1, 0).Value <> cel.Offset(2, 0) Then
MsgBox "Email(s) Created!"
End
End If
Next cel
MsgBox "Email(s) Created!"
End Sub
I have found the below code that will copy a filtered table and paste into the body of an email using HTML which is the end result I want for each different vendor. I can't figure out how to automate the macro to loop and filter the table to the next vendor in the table and then copy that lot of changed data to a new email.
Sub send_mass_email()
Dim i As Integer, cel As Range
Dim Name, Email, body, Subject, copy, Minesite, Workorder, str1, str2 As String
Dim OutApp As Object, OutMail As Object
Dim pop As Range
Set OutApp = CreateObject("Outlook.Application")
count_row = WorksheetFunction.CountA(Range("a1", Range("a1").End(xlDown)))
count_col = WorksheetFunction.CountA(Range("a1", Range("a1", "r1")))
Set pop = Sheets("Vendor Emails").Range(Cells(1, 5), Cells(count_row, count_col))
str1 = "<BODY style = font-size:12pt;font-family:Calibri>" & _
"Hello Team, <br><br> Can we please have an update on the purchase order/s below.<br>"
str2 = "<br>For further inforation please contact us below.<br>"
For Each cel In Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
Email = Split(cel, " ")(0) 'extract first name
Name = cel.Offset(, 2).Value
Subject = cel.Offset(, 4).Value
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = Email
.Subject = Subject & " " & Name & " PURCHASE ORDER UPDATES"
.display
.HTMLBody = str1 & RangetoHTML(pop) & str2 & .HTMLBody
'.Send
End With
If cel.Offset(1, 0).Value = cel.Offset(2, 0) Then
MsgBox "Email(s) Created!"
End
End If
If cel.Offset(1, 0).Value <> cel.Offset(2, 0) Then
MsgBox "Email(s) Created!"
End
End If
Next cel
MsgBox "Email(s) Created!"
End Sub