Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA中HTMLbody中的样式问题_Html_Excel_Vba_Format - Fatal编程技术网

VBA中HTMLbody中的样式问题

VBA中HTMLbody中的样式问题,html,excel,vba,format,Html,Excel,Vba,Format,我在使用VBA设置电子邮件正文时遇到问题。我需要定制不同字体大小和颜色的电子邮件正文。因此我使用了.HTMLBody函数。 有一次,我执行了代码,它工作正常,但在outlook显示中没有给出任何格式。 如果有人能在这个问题上提供帮助,我们将不胜感激 VBA代码: .HTMLBody = "Hi <strong>All</strong>" & "<br>" & "<br>"

我在使用VBA设置电子邮件正文时遇到问题。我需要定制不同字体大小和颜色的电子邮件正文。因此我使用了.HTMLBody函数。 有一次,我执行了代码,它工作正常,但在outlook显示中没有给出任何格式。 如果有人能在这个问题上提供帮助,我们将不胜感激

VBA代码:

 .HTMLBody = "Hi <strong>All</strong>" & "<br>" & "<br>" & _
                "Your task has already overdue! Please focus your kind attention here." & "<br>" & _
                "<br>" & _
                "<strong>" & "<span style=" & "color: rgb(41, 105, 176);" & ">" & "Task &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" & "</span>" & "</strong>:" & "<span style=" & "color: rgb(184, 49, 47);" & ">" & "testing task testing task" & "</span> " & "<br>" & _
                "<span style=" & "color: rgb(41, 105, 176);" & ">" & "<strong>" & "Decision" & "</strong>" & "</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:" & "<span style=" & "color: rgb(184, 49, 47);" & ">" & "Test action test action" & "</span>" & "<br>" & _
                "<span style=" & "color: rgb(41, 105, 176);" & ">" & "<strong>Due Date&nbsp;" & "</strong>" & "</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:" & "<span style=" & "color: rgb(184, 49, 47);" & ">" & "21/1/2021" & "</span>" & "<br>" & _
                "<br>" & "<br>" & "<br>" & _
                "<span style=" & "font-size: 12px;" & ">" & "This is system generated email from Measure and Monitoring team." & "</span>" & "<br>" & _
                "<span style=" & "font-size: 12px;" & ">" & "If you already completed or any convenience regarding this e mail please reply here." & "</span>" & "<br>" & _
                "<span style=" & "font-size: 10px;" & ">" & "Generated Date : 1/1/2021" & "</span>" & _
                "<br>"
.HTMLBody=“Hi所有”&“
”&“
”&”_ “您的任务已经过期!请将您的注意力集中在这里。”&“
”&_ “
”和_ “”&“&”任务“&”&“&”:“&”&“测试任务”&“&”&_ “&”“&”决策“&”“&”:“&”&”测试行动“测试行动”&“&”
“&”_ “&”到期日“&”“&”:“&”&“2021年1月21日”和“&”
”和_ “
”和“
”和“
”和_ “&”这是度量和监控团队通过系统生成的电子邮件_ “&”如果您已经完成了此电子邮件,或者有任何关于此电子邮件的便利,请在此处回复。”&“&”&”
“&”_ 生成日期:2021年1月1日_ “

那是因为你错了一半。如果它不工作,那么看看VBA将如何格式化它。一个错误: style=

自己测试一下:

Option Explicit
Sub test()
Dim HTMLBody As String

HTMLBody = "Hi <strong>All</strong>" & "<br>" & "<br>" & _
                "Your task has already overdue! Please focus your kind attention here." & "<br>" & _
                "<br>" & _
                "<strong>" & "<span style=" & "color: rgb(41, 105, 176);" & ">" & "Task &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" & "</span>" & "</strong>:" & "<span style=" & "color: rgb(184, 49, 47);" & ">" & "testing task testing task" & "</span> " & "<br>" & _
                "<span style=" & "color: rgb(41, 105, 176);" & ">" & "<strong>" & "Decision" & "</strong>" & "</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:" & "<span style=" & "color: rgb(184, 49, 47);" & ">" & "Test action test action" & "</span>" & "<br>" & _
                "<span style=" & "color: rgb(41, 105, 176);" & ">" & "<strong>Due Date&nbsp;" & "</strong>" & "</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:" & "<span style=" & "color: rgb(184, 49, 47);" & ">" & "21/1/2021" & "</span>" & "<br>" & _
                "<br>" & "<br>" & "<br>" & _
                "<span style=" & "font-size: 12px;" & ">" & "This is system generated email from Measure and Monitoring team." & "</span>" & "<br>" & _
                "<span style=" & "font-size: 12px;" & ">" & "If you already completed or any convenience regarding this e mail please reply here." & "</span>" & "<br>" & _
                "<span style=" & "font-size: 10px;" & ">" & "Generated Date : 1/1/2021" & "</span>" & _
                "<br>" & vbCrLf
Debug.Print HTMLBody

End Sub
选项显式
子测试()
Dim HTMLBody作为字符串
HTMLBody=“HiAll”&“
”&“
”&”_ “您的任务已经过期!请将您的注意力集中在这里。”&“
”&_ “
”和_ “”&“&”任务“&”&“&”:“&”&“测试任务”&“&”&_ “&”“&”决策“&”“&”:“&”&”测试行动“测试行动”&“&”
“&”_ “&”到期日“&”“&”:“&”&“2021年1月21日”和“&”
”和_ “
”和“
”和“
”和_ “&”这是度量和监控团队通过系统生成的电子邮件_ “&”如果您已经完成了此电子邮件,或者有任何关于此电子邮件的便利,请在此处回复。”&“&”&”
“&”_ 生成日期:2021年1月1日_ “
”&vbCrLf 调试。打印HTMLBody 端接头
我已经执行了代码,它工作正常,但没有在outlook显示中提供任何格式。这意味着什么?文本的格式为粗体,因此显然很有效。不,我需要给那个词加上颜色。我使用“嗨,如果我在style=”之后删除引号,它会给我一个错误,代码不起作用。您能告诉我们您当时遇到了什么错误吗?错误是指如果我删除引号,请按以下方式编写代码,&“”&”“&它没有任何颜色。它只加粗了文本。和我在图中显示的结果相同。您不能删除引号,这是无效的CSS。请告诉我们您在使用引号时遇到了什么错误。