使用 HTMLBody 进行条件格式化

Conditional formatting with HTMLBody

下面的代码根据条件复制预定义的范围。 "Range function" 中 "Else" 行中的代码必须看起来像什么,以便当 criteria = 0 时,只有 strText2 中的文本被获取并粘贴到电子邮件正文中?问题是我可能需要两个 .HTMLBody 代码,例如:

标准 > 1

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

条件 = 0

  .HTMLBody = strText2 

获取锅炉函数:

Function GetBoiler(ByVal sFile As String) As String
Dim fso As Object
Dim ts As Object

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)

GetBoiler = ts.readall

ts.Close
End Function

范围函数: 函数 RangetoHTML(rng 作为范围)

Dim fso As Object
Dim ts As Object
Dim 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

Dim datDatum As Date
Dim StrBody As String
Dim intZeile As Integer
Dim OutMail As Object
Dim rng As Range

Dim strMailverteilerTo As String
Dim strText As String
Dim strFilename As String
Dim 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

它以某种方式工作。好像没有错