Line height in an E-Mail (HTML) created with Excel

2019-09-19 10:35发布

I have the following VBA Code to create an E-Mail within an Excel spreadsheet:

Sub Test_EMail()
    If ExitAll = False Then
        Dim OApp As Object, OMail As Object, signature As String
        Set OApp = CreateObject("Outlook.Application")
        Set OMail = OApp.CreateItem(0)
            With OMail
            .Display
            End With
            signature = OMail.HTMLbody
            With OMail
            .To = "test@test.de"
            .Subject = "test"
            .HTMLbody = "<p> Hello </p>" _
            & vbCr & "<p> I want to have a specific line hight because this </p>" _
            & vbCr & "<p> line height is too much space </p>" _
            & vbCr & "<p> How I can decrease this line height? </p>"
            End With
        Set OMail = Nothing
        Set OApp = Nothing
    Else
    End If
End Sub

The code itself works perfectly. However, when I see the E-Mail there is a big line height between the three sentences written with HTML.

If I try to go with this:

& vbCr & <p style="line-height: 50%">I want to have a specific line hight because this</p>

it also does not work which might be due to the mixing of a VBA and HTML Code.

Do you have any idea how I can change the line height in the E-Mail within the VBA code?

1条回答
在下西门庆
2楼-- · 2019-09-19 10:43

Since this is an HTML format email, the HTML opening and closing tags must also be inserted.

Dim body_ As String
    body_= "<p> Hello </p>" _
         & "<p> I want to have a specific line hight because this </p>" _
         & "<p> line height is too much space </p>" _
         & "<p> How I can decrease this line height? </p>"

.BodyFormat = olFormatHTML
.HTMLBody = "<html><head></head><body>" & body_ & "</body></html>"
查看更多
登录 后发表回答