我知道我的代码非常笨拙,我正尽力做出一些事情。
背后的想法是拥有一张包含所有相关细节的Excel表格,并根据此表格发送带有相关内容的电子邮件。
电子邮件以strbody = Cells开头(cell.Row," A")。细胞(cell.Row," B")。值_
这里是cell.row A是问候语(亲爱的先生或亲爱的女士)和cell.row B是这个人的名字。
如果我运行代码,一切正常,但这段代码的字体搞砸了。它显示了新的罗马时代,但我希望它有一个大小:10pt。我尝试了一切,但总是得到错误。
有什么想法吗?
提前致谢。
Sub test1()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim strbody As String
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error GoTo cleanup
For Each cell In Columns("C").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "D").Value) = "ENG" Then
On Error Resume Next
With OutMail
.display
strbody = Cells(cell.Row, "A").Value & Cells(cell.Row, "B").Value _
& "<p style= font-family:arial;font-size:10pt> Welcome </p>" _
& IIf(Cells(cell.Row, "G").Value = "incomplete", "<p style= font-family:arial;font-size:10pt>Please do not forget to complete your registration:<p/> " & Cells(cell.Row, "F").Value, "<p> <p/>") _
& "<h3 style= font-family:arial;font-size:11pt><font color=#5b9bd5><u>Check-in & Check-out</u></font></h3>" _
& "<p style= font-family:arial;font-size:10pt>Check-In: <b>ab 15:00 Uhr</b> & Check-out: <b>bis 10:00 Uhr</b> Other hours on request </p>" _
& "<p style= font-family:arial;font-size:10pt>Thanks</b></p>" _
.Attachments.Add ("G:\E-Mail Vorlagen\Anhang\Anreise Infos\Nützliche Informationen.pdf")
.To = Cells(cell.Row, "C").Value
.Subject = "Your arrival" & Cells(cell.Row, "E").Value
.htmlbody = strbody & .htmlbody
.BodyFormat = olFormatHTML
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
使用单引号(即 ticks )来隔离样式命令。
...
& "<p style='font-family:arial;font-size:10pt;'> Welcome </p>"
...