The code below sends a mail in outlook from an excel model (composed in cell H3). The problem is the mail content in h3 is separated out in different paragraphs that I would like to be carried over to the actual email body in outlook. Unfortunately when the email comes out, it is all compressed into one long sting without paragraphs or spaces demarcated.
Can someone suggest what tweaks could work: (please note that the ".htmlbody" was adopted in order to maintain the signature logo in the email)
The code:
Sub DelaySendingEmail()
Dim Msg As String
Dim olApp As Object
Dim olEmail As Object
Dim SendAt As String
Dim SendTo As String
Dim Subj As String
Dim signature As String
''''''''''''''''''
''''''''''''''''''
For i = Range("b1").Value To Range("d1").Value
''''''''''''''''''
''''''''''''''''''
Range("recipient").Value = Cells(10 + i, 1).Value
Range("e3").Value = Cells(10 + i, 7).Value
subje = Range("h2").Value
mes = Range("h3").Value
SendTo = Range("recipient").Value
Subj = subje
Msg = mes
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err = 429 Then
Err.Clear
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0
olApp.Session.Logon
Set olEmail = olApp.CreateItem(olMailItem)
''
With olEmail
.Display
End With
signature = olEmail.HTMLbody
''
With olEmail
' .DeferredDeliveryTime = SendAt
.To = SendTo
.Subject = Subj
.HTMLbody = Msg & vbNewLine & signature
.Send
End With
olApp.Session.Logoff
Set olApp = Nothing
Set olEmail = Nothing
Next i
End Sub
Can someone suggest what tweaks could work: (please note that the ".htmlbody" was adopted in order to maintain the signature logo in the email)
The code:
Sub DelaySendingEmail()
Dim Msg As String
Dim olApp As Object
Dim olEmail As Object
Dim SendAt As String
Dim SendTo As String
Dim Subj As String
Dim signature As String
''''''''''''''''''
''''''''''''''''''
For i = Range("b1").Value To Range("d1").Value
''''''''''''''''''
''''''''''''''''''
Range("recipient").Value = Cells(10 + i, 1).Value
Range("e3").Value = Cells(10 + i, 7).Value
subje = Range("h2").Value
mes = Range("h3").Value
SendTo = Range("recipient").Value
Subj = subje
Msg = mes
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err = 429 Then
Err.Clear
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0
olApp.Session.Logon
Set olEmail = olApp.CreateItem(olMailItem)
''
With olEmail
.Display
End With
signature = olEmail.HTMLbody
''
With olEmail
' .DeferredDeliveryTime = SendAt
.To = SendTo
.Subject = Subj
.HTMLbody = Msg & vbNewLine & signature
.Send
End With
olApp.Session.Logoff
Set olApp = Nothing
Set olEmail = Nothing
Next i
End Sub