将条件格式设置为 HTMLBody

Getting the conditional formatting into the HTMLBody

有没有可能HTML正文:

.HTMLBody = strText & RangetoHTML(rng) & "<br><br>" & GetBoiler(Environ("appdata") & "\Microsoft\Signatures\" & strFilename & ".htm")

...当 criteria > 1 满足并且...

.HTMLBody = strText2 & "<br><br>" & GetBoiler(Environ("appdata") & "\Microsoft\Signatures\" & strFilename & ".htm")

' 在这种情况下,范围缺失,当满足 criteria = 0 时文本不同。

我想到了"if"函数进入HTML正文?

获取锅炉函数:

Function GetBoiler(ByVal sFile As String) As String
    Dim fso As Object, ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.readall
    ts.Close
End Function

范围函数:

Function RangetoHTML(rng As Range)
    Dim fso As Object, ts As Object, TempWB As Workbook
    With Worksheets("Auswertung")
        loLetzte = .Cells(.Rows.Count, 1).End(xlUp).Row
        .Range("$A:$D$" & loLetzte).AutoFilter Field:=3, Criteria1:=">0"
        If .AutoFilter.Range.SpecialCells(xlCellTypeVisible).Rows.Count > 1 Then
            .AutoFilter.Range.Offset(1).Resize(.AutoFilter.Range.Rows.Count - 1). _
                    SpecialCells(xlCellTypeVisible).Copy
        Else
            'copy only the strText2
        End If
        .AutoFilterMode = False
    End With
End Function

主要子功能:

Sub Mail_Klicken()
    Dim olApp As Object, datDatum As Date, StrBody As String, intZeile As Integer
    Dim OutMail As Object, rng As Range, strMailverteilerTo As String
    Dim strText As String, strFilename As String, loLetzte As Long
    strMailverteilerTo = "sdfgsdf@gmx.de"
    strText = "<span style='font-size:10.0pt;font-family:""Arial"",""sans" & _
        "-serif"";color:black'>hello,<br><br>hello fellows.<br><br>"
    strText2 = "<span style='font-size:10.0pt;font-family:""Arial"",""sans" & _
        "-serif"";color:black'>dfgfg,<br><br>gfgfgfgfg.<br><br>"
    Application.DisplayAlerts = True
    Set rng = Selection.SpecialCells(xlCellTypeVisible)
    Set olApp = CreateObject("Outlook.Application")
    With olApp.CreateItem(0)
        .to = strMailverteilerTo
        .Subject = "check"
        strFilename = "Standard"
        If Application.UserName = "asd" Then strFilename = "asd"
        .HTMLBody = strText & RangetoHTML(rng) & "<br><br>" & _
            GetBoiler(Environ("appdata") & "\Microsoft\Signatures\" & _
            strFilename & ".htm")
        .Display
    End With
    Set olApp = Nothing
End Sub

据我所知,你不能写这样的语句,因为它需要一个字符串参数,你可以这样做的一种方法是调用一个构建字符串的函数,

Set olApp = CreateObject("Outlook.Application")
setStrText criteria, strText, rng 
With olApp.CreateItem(0)
'rest of your code
    .HTMLBody = strText
'rest of your code

function setStrText(crit as integer, strTe as string, tmpRng as range)
    if crit >= 1 then
        strTe = "<span style='font-size:10.0pt;font-family:""Arial"",""sans" & "-serif"";color:black'>hello,<br><br>hello fellows.<br><br>" & RangetoHTML(tmpRng) & "<br><br>" & GetBoiler(Environ("appdata") & "\Microsoft\Signatures\" & strFilename & ".htm")
    else
        strTe = "<span style='font-size:10.0pt;font-family:""Arial"",""sans" & "-serif"";color:black'>dfgfg,<br><br>gfgfgfgfg.<br><br>" & "<br><br>" & GetBoiler(Environ("appdata") & "\Microsoft\Signatures\" & strFilename & ".htm")
    end if
end function