Body of email

charlee63

Board Regular
Joined
Jan 7, 2010
Messages
146
I have a program I am trying to make
Sub Email()
' Call startIt
' Set Tabs
Dim WSX As Worksheet
Dim WSY As Worksheet
Set WSX = Worksheets("Email")
Set WSY = Worksheets("Vendor Tracker")

' How many rows in File

Dim LastRow As Long
LastRow = WSX.Cells(Rows.Count, "F").End(xlUp).Row
Count = 0

Dim objNotif_Email
Dim dist_list
Dim email_from As String
Dim email_subject
Dim email_body As String
Dim filepath As String
Dim new_report
x = 2
' For x = 2 To LastRow
'Setting fields
WSX.Cells(4, "B") = WSX.Cells(x, "F")
Vendor = WSX.Cells(4, "B")
email_from = WSX.Cells(5, "B")
dist_list = WSX.Cells(6, "B")
' email_body = WSX.Cells(7, "B")
email_body = WSX.Cells(10, "B").Value & _
vbNewLine & _
vbNewLine & _
WSX.Cells(12, "B").Value & _
"<a href=""2023 Trade Fund Survey"">2023 Trade Fund Survey </a>" & _
vbNewLine & _
vbNewLine & _
WSX.Cells(33, "B").Value
email_subject = WSX.Cells(8, "B")
If dist_list = "" Then
Count = Count + 1
' WSY.Cells(WSX.Cells(4, "C").Value, "E").Value = "Not sent"
GoTo Line
End If
' Doing email
MyPath = WSX.Cells(2, "B").Value ' Set the path.
MyName = WSX.Cells(3, "B").Value
MyFile = MyPath & MyName
Set objNotif_Email = CreateObject("CDO.Message")
With objNotif_Email
.From = email_from
.To = dist_list
.Subject = email_subject
.HTMLBody = email_body
.AddAttachment MyFile

'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp-relay.cswg.com"
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MerchandisingTeam"
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "123"
.Configuration.Fields.Update
'==End remote SMTP server configuration section==
' objNotif_Email.Display Does not suppot
.send
End With ' Moving Sent files

Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
' FSO.MoveFile MyPath & MyName, MyPath & "Sent\" & MyName
' WSY.Cells(WSX.Cells(4, "C").Value, "E").Value = Format(Date, "mm-dd-yyyy")
Line:
' Next x

MsgBox ("Email Sent - " & Count & " did not get sent")
End Sub

Everything work except vbNewLine
This is what I get

Dear manufacturer/ broker, The C&S supplied Independent retailers are a critical part of the food industry, and it is vital that the2023 Trade Fund Survey Thank you

This is what I want

Dear manufacturer/ broker,
The C&S supplied Independent retailers are a critical part of the food industry, and it is vital that the
2023 Trade Fund Survey

Thank you

Why is the New Line not working?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
for giggles, replace vbNewLine with <br>
office isn't interpreting the body of your text, html is. Just give it a try
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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