在HTML文本正文(VBA + Outlook)中引用if函数中的单元格导致问题

问题描述 投票:0回答:1

我是新手,所以请原谅我的新手问题。我有以下iff函数和对单元格的引用导致语法问题,因此它无法正常工作...

Sub test1()
Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range
    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")
    On Error GoTo cleanup

    For Each cell In Columns("C").Cells.SpecialCells(xlCellTypeConstants)
    If cell.Value Like "?*@?*.?*" And _
       LCase(Cells(cell.Row, "D").Value) = "de" Then
        Set OutMail = OutApp.CreateItem(0)
        On Error Resume Next
       With OutMail
            .To = Cells(cell.Row, "C").Value
            .Subject = "Your arrival in Vienna " & Cells(cell.Row, "E").Value

              .BodyFormat = olFormatHTML
.HTMLBody = Cells(cell.Row, "A").Value & Cells(cell.Row, "B").Value _
& IIf(Cells(cell.Row, "G").Value = "incomplete", "<p>Your invoice is incomplete, please find below the payment link:<p/> & Cells(cell.Row, "F").Value", "<p> <p/>") 
.Display

        End With
        On Error GoTo 0
        Set OutMail = Nothing
    End If
Next cell


cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub

如果我在F in和Cells之间包含“”(cell.Row,“F”)。值“在列表分隔符中说”或“ - 请原谅,我的Excel是德语。

如果我在F中向下排除引用和单元格(cell.Row,F).Value之间的“”作为字符串,它出现在电子邮件模板中。

有任何想法吗?非常非常感谢你!

html excel vba outlook
1个回答
0
投票

不确定HTML外观但是

Option Explicit

Sub test1()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range

    Application.ScreenUpdating = False

    Set OutApp = CreateObject("Outlook.Application")

    On Error GoTo cleanup

    For Each cell In Columns("C").Cells.SpecialCells(xlCellTypeConstants)

        If cell.Value Like "?*@?*.?*" And _
           LCase(Cells(cell.Row, "D").Value) = "de" Then

            Set OutMail = OutApp.CreateItem(0)

            On Error Resume Next

            With OutMail

                .To = Cells(cell.Row, "C").Value

                .Subject = "Your arrival in Vienna " & Cells(cell.Row, "E").Value

                .BodyFormat = olFormatHTML

                .HTMLBody = Cells(cell.Row, "A").Value & Cells(cell.Row, "B").Value _
                                                                      & IIf(Cells(cell.Row, "G").Value = "incomplete", "<p>Your invoice is incomplete, please find below the payment link:<p/> " & Cells(cell.Row, "F").Value, "<p> <p/>")
                .Display

            End With

            On Error GoTo 0

            Set OutMail = Nothing

        End If

    Next cell


cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.