VBA HTML Email Issue

jamesmev

Board Regular
Joined
Apr 9, 2015
Messages
233
Office Version
  1. 365
Platform
  1. Windows
I am using the below:
However, When executing the code the email is only outputting the final line.
I'm unsure why the rest of the code isn't taking.


Sub SendByOne()
Dim c As Range
Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim i As Integer
On Error Resume Next


For Each c In Range("B2:B2" & Cells(Rows.Count, "B").End(xlUp).Row).Cells
Set OutLookApp = CreateObject("Outlook.application")
Set OutLookMailItem = OutLookApp.CreateItem(0)
With OutLookMailItem
.From = """biz name""<ccccustomerdevelopment@bizname.com>"
'.To = c.Offset(0, 4).Value
.To = "jevereth@coke-bsna.com"
.Subject = c.Offset(0, 1).Value

.htmlbody = ""
.htmlbody = "<b>" & "Bottler :" & " " & c.Offset(0, 1).Value & "</b>" & vbNewLine
.htmlbody = "Sales Office" & c.Offset(0, 17).Value & "</b>" & vbNewLine_
.htmlbody = "POM" & c.Offset(0, 3).Value & "</b>" & vbNewLine_
.htmlbody = "Notes" & c.Offset(0, 9).Value & "</b>" & vbNewLine_

.htmlbody = "Correction -- " & " Required Information" & "<\b>" & vbNewLine_
.htmlbody = "Customer Number -- " & c.Offset(0, 12).Value & "</b>" & vbNewLine_
.htmlbody = "Customer Name -- " & c.Offset(0, 11).Value & "</b>" & vbNewLine_
.htmlbody = "12 month Volume -- " & c.Offset(0, 18).Value & "</b>" & vbNewLine_
.htmlbody = "Sales Office -- " & c.Offset(0, 17).Value & " " & c.Offset(0, 15).Value & "</b>" & vbNewLine_
.htmlbody = "OWNER -- " & c.Offset(0, 1).Value & "</b>" & vbNewLine_
.htmlbody = "New Call Frequency -- " & c.Offset(0, 5).Value & "</b>" & vbNewLine_
.htmlbody = "Delivery Day Decrease -- " & c.Offset(0, 4).Value & "</b>" & vbNewLine_
.htmlbody = "Delivery Day Increase -- " & c.Offset(0, 8).Value & "</b>" & vbNewLine_
.htmlbody = "New/Add/ Change Delivery Day -- " & c.Offset(0, 6).Value & "</b>" & vbNewLine_
.htmlbody = "New/Add/Change Call Day -- " & c.Offset(0, 7).Value & "</b>" & vbNewLine_
.htmlbody = "Delivery Window Update -- " & c.Offset(0, 10).Value & "</b>" & vbNewLine_


.htmlbody = "<br> <br> Thank you in advance for your assistance and prompt attention to this request."


' .HTmlbody = .HTmlbody & "<br>If you would like to embed my latest video you can find it here"
' .HTmlbody = .HTmlbody & "<br> Check it out <a href = ""URL HERE""> HERE </a>"
.display 'to display first
'.Send 'to send it in background
End With
Next c

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Amend your code like this ...

Rich (BB code):
.htmlbody = .htmlbody & "<b>" & "Bottler :" & " " & c.Offset(0, 1).Value & "</b>" & vbNewLine
.htmlbody = .htmlbody & "Sales Office" & c.Offset(0, 17).Value & "</b>" & vbNewLine
'
'
 
Upvote 0
i can't believe i missed that.. Thank you.
Next issue - is that it keeps sending even if nothing is in "B". Why is that?
 
Upvote 0
Let me guess, you removed the 2
Rich (BB code):
For Each c In Range("B2:B2" & Cells(Rows.Count, "B").End(xlUp).Row).Cells
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top