Создание HTML-почты для Outlook с масштабированным фоновым изображением через Excel VBA - PullRequest
1 голос
/ 04 июня 2019

Я пытаюсь сгенерировать несколько писем с текстовым телом и масштабированным фоновым изображением.Все работает, единственная проблема в том, что фоновое изображение появляется много раз, а не один раз с правильным масштабом.

Установка фонового изображения с помощью HTML в электронном письме Outlook с помощью Excel VBA

Я пробовал этот подход, но код

MyHTML = "<body background=""cid:Pic1.jpg""; center top no-repeat;>"

не работает для меня.

Sub FORMATIERUNG_TESTEN()
    Dim objOLOutlook As Object
    Dim objOLMail As Object
    Dim lngMailNr As Long
    Dim lngZaehler As Long
    Dim strAttachmentPfad1 As String
    Dim a As String
    Dim image As String
    Dim strbody As String
    Dim MyHTML As String
    Dim MyText As String
    On Error GoTo ErrorHandler


    Set objOLOutlook = CreateObject("Outlook.Application")
    lngMailNr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row

    strAttachmentPfad1 = "C:\Users\User\Downloads\Pic1.jpg"


       'running through every not empty line of column a to get the email adresses

        For lngZaehler = 2 To lngMailNr
            If Cells(lngZaehler, 1) <> "" Then
                Set objOLMail = objOLOutlook.CreateItem(olMailItem)
                On Error Resume Next
                With objOLMail
                    .To = Cells(lngZaehler, 1)
                    .CC = Cells(lngZaehler, 2)
                    .BCC = ""
                    .Sensitivity = 0
                    .Importance = 0
                    .Subject = "Test"

        'creating the text body of the mail                     

                    strbody = "<font size=""2,9"" face=""Source Sans Pro"" color=""#2F5496"">" & _
                    "TEXT TEXT TEXT TEXT TEXT" & "</font>"

        'here is the problem: I get the background image in the mail, but the "no repeat" command does not work

                      MyHTML = "<body background=""cid:Pic1.jpg""; center top no-repeat;>"


                    .HTMLBody = MyHTML & "<br>" & "<br>" & "<br>" & strbody & "<br>" & "<br>" & "<br>" & "<br>" & "<img src = 'Signature.jpg' >"

                    .Display
                    '.Send
                    .Attachments.Add strAttachmentPfad1

                    End With
                    Set objOLMail = Nothing
                End If
            Next lngZaehler
            Set objOLOutlook = Nothing
    Exit Sub

ErrorHandler:
    MsgBox Err.Number & " " & Err.Description & " " & Err.Source, _
    vbInformation, "Error"

End Sub
...