Results 1 to 3 of 3

Thread: I need help to edit my vba code for the wrapped text

  1. #1
    VBAX Newbie
    Sep 2023

    I need help to edit my vba code for the wrapped text

    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)
            Signature = msg.HTMLBody
            msg.To = sh.Range("D" & i).Value
   = 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
            End If
            sh.Range("B" & i).Value = "Done"
        End If
    Next i
    MsgBox "Process Completed!!!", vbInformation
    End Sub
    Attached Files Attached Files
    Last edited by Aussiebear; 09-13-2023 at 04:28 PM. Reason: Added code tags to supplied code

  2. #2
    See attached, however without data in your worksheet it is not possible to test whether it works as you require.
    Attached Files Attached Files
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes

  3. #3
    Moderator VBAX Guru Aussiebear's Avatar
    Dec 2005
    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.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts