如何格式化htmlbody中的段落间距



我已经使用Excel宏写了一封Outlook电子邮件。线的段落间距设置为"自动"。我希望在之前和之后的间距为" 0 pt"。

有没有办法决定适当的段落格式?

Sub Email_Budget()
   Dim objOutlook As Object
   Set objOutlook = CreateObject("Outlook.Application")
   Dim objEmail As Object
   Set objEmail = objOutlook.CreateItem(olMailItem)
   Dim CaseCount As Long
   CaseCount = WorksheetFunction.CountA(Range("B6:B500"))
   'Debug.Print CaseCount
   Dim i As Integer
   With objEmail
      .To = "abc@xyz.com"
      .Subject = "TEST1: May 2019 Budget"
      .HTMLBody = "Karen,<br><br>"
      .HTMLBody = .HTMLBody & "The potential " & _
        MonthName(Month(ActiveSheet.Range("A2"))) & _
        " invoices are below.<br><br>"
      For i = 1 To CaseCount
          If ActiveSheet.Cells(i + 5, 4).Value = "Yes" Then
              .HTMLBody = .HTMLBody & "<ul style='list-style-type:disc;'>" & _
                "<li>" & ActiveSheet.Cells(i + 5, 2).Value & " - " & _
                Format(ActiveSheet.Cells(i + 5, 6).Value, "Currency") & _
                " (" & Format(ActiveSheet.Cells(i + 5, 8).Value, "Currency") & _
                " without budget or invoicing)." & "</li>" & "</ul>"
          End If
      Next i
      .HTMLBody = .HTMLBody & "<br>Thank you,<br>Kurt"
      .Display
   End With
End Sub

这样的格式化电子邮件的最简单方法是在Outlook中以格式编写电子邮件,将其发送给您自己,然后右键单击电子邮件的主体,然后选择"视图源"。然后,您可以选择HTML的相关部分。

在您的情况下,我相信您想添加这两种样式选项以设置间距之前/之后:

style='mso-margin-top-alt:0.0pt;margin-bottom:0.0pt;'

您正在为每个列表项目编写<ul></ul> - 您应该在输入循环之前写<ul>,然后在循环完成时</ul>。修复可能可以解决您的间距问题

   With objEmail
      .To = "abc@xyz.com"
      .Subject = "TEST1: May 2019 Budget"
      .HTMLBody = "Karen,<br><br>"
      .HTMLBody = .HTMLBody & "The potential " & _
                  MonthName(Month(ActiveSheet.Range("A2"))) & _
                  " invoices are below.<br><br><ul style='list-style-type:disc;'>"
      For i = 1 To CaseCount
        If ActiveSheet.Cells(i + 5, 4).Value = "Yes" Then
            .HTMLBody = .HTMLBody & "<li>" & ActiveSheet.Cells(i + 5, 2).Value & _
                        " - " & Format(ActiveSheet.Cells(i + 5, 6).Value, "Currency") & _
                        " (" & Format(ActiveSheet.Cells(i + 5, 8).Value, "Currency") & _
                        " without budget or invoicing)." & "</li>"

        End If
      Next i
      .HTMLBody = .HTMLBody & "</ul><br>Thank you,<br>Kurt"
      .Display
   End With

最新更新