DGMS89
DGMS89

Reputation: 1667

Creating a line break in html

Scenario: I am trying to meddle with the output of an email that is going to be sent with VBA. I am trying to add a background image and a piece of text.

Issue: The image part is working properly, but I am not being able to get the text to be divided in 3 lines.

Obs: I never used HTML in my life, but apparently it is the only way to change the background of my email with VBA. I tried looking for an answer online, but the best I got was to use <br> which is not working for me.

Question: What is the proper way to do this?

Code:

Private Sub mailer2()
Dim oApp, oMail As Object, MyHTML As String, WB As Workbook, FileName As String, BodyText As String, MyText As String, MyText2 As String, MyText3 As String
Dim username As String

    Application.ScreenUpdating = False

    Set oApp = CreateObject("Outlook.Application")
    Set oMail = oApp.CreateItem(0)

    username = InputBox("Please write your E-mail")

    MyText = "Greetings"
    MyText2 = "Your Macro.V.0.4 has concluded."
    MyText = "Please attend to terminal AFAP"


    MyHTML = vbCrLf & "<p style=""font-size:18px;font-weight:Bold;color:rgb(100,100,100)"">" & MyText1 & "<br>" & MyText2 & "<br>" & MyText3 & "</p>"

    'this next works, but puts everything into a single line
    'MyHTML = MyHTML & vbCrLf & "<p style=""font-size:19px;font-weight:Bold;color:rgb(100,100,100)"">" & MyText & "</p>"

    With oMail
        .To = username
        .Subject = "Automated message, please do not answer"
        .HTMLBody = MyHTML
        .Send
    End With

    Application.ScreenUpdating = True
    Set oMail = Nothing
    Set oApp = Nothing

End Sub

Upvotes: 0

Views: 674

Answers (2)

SteliosKts
SteliosKts

Reputation: 65

Other than what brax said (<br>) you can use the horizontal rule tag <hr>. Put any one of those between the texts you want to divide.

EDIT: try removing " " of your html. tags are used without those.

EDIT2: Nevermind my first edit, i misread your code. Try <br><br>. It should work.

In general, your question was a pretty basic one. Next time try to dig some more before making a post. It's easy to answer questions like this.

Upvotes: 1

braX
braX

Reputation: 11755

You can use the HTML for a line break:

<br>

Upvotes: 0

Related Questions