PDA

View Full Version : I need help to edit my vba code for the wrapped text



johara
09-13-2023, 09:04 AM
Hi, I am using html.body for my email body to have the signature in the email. However, my text all become one line. can anyone help to edit the coding? Appreciate your help.



Sub Send_Mails()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Bulk Email")
Dim i As Integer
Dim OA As Object
Dim msg As Object
Set OA = CreateObject("outlook.application")
Dim last_row As Integer
Dim Signature As String
Dim bodyMain As String
last_row = sh.Range("D" & Application.Rows.Count).End(xlUp).Row
For i = 6 To last_row
If UCase(sh.Range("A" & i).Value) <> "YES" Then
Set msg = OA.createitem(0)
If sh.Range("C" & i).Value <> "" Then msg.SentOnBehalfOfName = sh.Range("C" & i).Value
Set msg.SendUsingAccount = OA.Session.Accounts.Item(1)
msg.display
Signature = msg.HTMLBody
msg.To = sh.Range("D" & i).Value
msg.cc = sh.Range("E" & i).Value
msg.Subject = sh.Range("F" & i).Value
msg.body = sh.Range("G" & i).Value
msg.HTMLBody = sh.Range("G" & i).Value & vbNewLine & Signature
If sh.Range("H" & i).Value <> "" Then
msg.attachments.Add sh.Range("H" & i).Value
End If
If sh.Range("I" & i).Value <> "" Then
msg.attachments.Add sh.Range("I" & i).Value
End If
If sh.Range("J" & i).Value <> "" Then
msg.attachments.Add sh.Range("J" & i).Value
End If
If sh.Range("K" & i).Value <> "" Then
msg.attachments.Add sh.Range("K" & i).Value
End If
If sh.Range("A1").Value = 1 Then
msg.send
Else
msg.display
End If
sh.Range("B" & i).Value = "Done"
End If
Next i
MsgBox "Process Completed!!!", vbInformation
End Sub

gmayor
09-13-2023, 09:41 AM
See attached, however without data in your worksheet it is not possible to test whether it works as you require.

Aussiebear
09-13-2023, 04:39 PM
Welcome to VBAX Johara. I have taken the liberty to move your post to a new thread, and enclosed your supplied code with code tags.