如何使用Excel宏修改项目符号?

时间:2019-05-08 15:14:08

标签: html excel vba outlook-vba

快速提问:

您如何格式化实际的项目符号点本身?项目符号点都仍然显示为星号,而不是第一个项目符号的普通黑圈和子项目符号的空心圆。我尝试定义样式,但是当我添加“ list-style-type:disc;”时,代码给我一条错误消息。

使用w3schools,我知道它应该如何工作,但在Excel VBA中似乎不起作用。任何帮助将不胜感激!

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"
      .Body = "Kurt,"
      .Body = .Body & " "
      .Body = .Body & "The potential " & MonthName(Month(ActiveSheet.Range("A2"))) & " invoices are below."
      .Body = .Body & " "
      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>" & "<li>" & "Last billed " & ActiveSheet.Cells(i + 5, 10) & "." & "</li>" & "</ul>" & "</ul>"
        End If
      Next i
      .Body = .Body & " "
      .Body = .Body & " "
      .Body = .Body & "Thank you,"
      .Body = .Body & "Karen"
      .Display
   End With
End Sub


1 个答案:

答案 0 :(得分:0)

为了创建多级列表,您可以简单地构造另一个<ul>嵌套在您的<li>物品之一下方的列表。您可以在此处修改HTML:

http://w3schools.com/code/tryit.asp?filename=G3UBZA6VM2WS

要控制单个<li>项目的列表项样式,请指定其为type attribute`。

要为列表中的所有项设置列表项样式,请使用相应的CSS指定style attribute,例如:

"<ul style='list-style-type:disc'>"

请注意在带引号的字符串中使用单引号:)

最后,我现在怀疑这一直是您的问题(光盘样式似乎是Outlook中的默认样式,因此您可能不需要这样指定):

您不能混用.Body.HTMLBody。您需要使用其中一个。如果您使用.Body,则电子邮件将为纯文本,并且接受或呈现HTML。因此,您应该将所有.Body分配都转换为适当的.HTMLBody。未经测试,但应该是这样的:

With objEmail
    .To = "abc@xyz.com"
    .Subject = "TEST1: May 2019 Budget"
    .HTMLBody = "Kurt,"
    .HTMLBody = .HTMLBody & "<br>"
    .HTMLBody = .HTMLBody & "<p>The potential " & MonthName(Month(ActiveSheet.Range("A2"))) & " invoices are below.</p>"
    .HTMLBody = .HTMLBody & "<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>" & "<li>" & "Last billed " & ActiveSheet.Cells(i + 5, 10) & "." & "</li>" & "</ul>" & "</ul>"
        End If
    Next i
    .HTMLBody = .HTMLBody & "<br><br>"
    .HTMLBody = .HTMLBody & "<p>" & "Thank you," & "</p>" 
    .HTMLBody = .HTMLBody & "<p>" & "Karen" & "</p>" 
    .Display
End With