HTMLBody的条件格式

时间:2018-09-07 13:00:57

标签: html copy range paste

下面的代码根据条件复制了预定义的范围。 “条件函数”中“其他”行中的代码应具有什么样的外观,以便当条件= 0时,仅采用strText2中的文本并将其粘贴到电子邮件正文中?问题是我可能需要两个.HTMLBody代码,例如:

对于条件> 1

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

对于条件= 0

  .HTMLBody = strText2 

GetBoiler函数:

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$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

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

1 个答案:

答案 0 :(得分:0)

它以某种方式起作用。似乎没有错误