将条件格式设置到HTMLBody中

将条件格式设置到HTMLBody中,html,excel,vba,conditional,Html,Excel,Vba,Conditional,是否可以使用HTML正文: .HTMLBody=strText&RangetoHTML(rng)&“”&GetBoiler(环境(“appdata”)&“\Microsoft\Signatures\”&strFilename&“.htm”) …当满足标准>1且 .HTMLBody=strText2&“”&GetBoiler(环境(“appdata”)&“\Microsoft\Signatures\”&strFilename&“.htm”) '在这种情况下,当满足criteria=0时,范围缺失,

是否可以使用HTML正文:

.HTMLBody=strText&RangetoHTML(rng)&“

”&GetBoiler(环境(“appdata”)&“\Microsoft\Signatures\”&strFilename&“.htm”)

…当满足
标准>1

.HTMLBody=strText2&“

”&GetBoiler(环境(“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$7:$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
范围功能:

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$7:$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
主要子功能:

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$7:$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
Sub-Mail_Klicken()
Dim olApp作为对象,datdatam作为日期,StrBody作为字符串,intZeile作为整数
Dim OutMail作为对象,rng作为范围,strMailverteilerTo作为字符串
Dim strText作为字符串,strFilename作为字符串,loLetzte作为长字符串
strMailverteilerTo=”sdfgsdf@gmx.de"
strText=“你好,

大家好。

” strText2=“dfgfg,

gfg.

” Application.DisplayAlerts=True 设置rng=Selection.SpecialCells(xlCellTypeVisible) 设置olApp=CreateObject(“Outlook.Application”) 使用olApp.CreateItem(0) .to=strMailverteilerTo .Subject=“检查” strFilename=“标准” 如果Application.UserName=“asd”,则strFilename=“asd” .HTMLBody=strText&RangetoHTML(rng)&“

”和_ GetBoiler(环境(“appdata”)和“\Microsoft\Signatures\”和_ strFilename&“.htm”) .展示 以 设置olApp=Nothing 端接头
您不能这样写语句,因为它需要一个字符串参数,这里有一种方法,您可以调用一个生成字符串的函数

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
Set olApp=CreateObject(“Outlook.Application”)
设置文本标准,strText,rng
使用olApp.CreateItem(0)
'代码的其余部分
.HTMLBody=strText
'代码的其余部分
函数setStrText(crit为整数,strTe为字符串,tmpRng为范围)
如果临界值>=1,则
strTe=“你好,

大家好。

”&RangetoHTML(tmpRng)和“

”&GetBoiler(Environ(“appdata”)和“\Microsoft\Signatures\”&strFilename&.htm”) 其他的 strTe=“dfgfg,

gfg.

”和“

”&GetBoiler(环境(“appdata”)和“\Microsoft\Signatures\”&strFilename&.htm”) 如果结束 端函数