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?
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?