【发布时间】:2020-06-25 07:28:42
【问题描述】:
我知道我的代码很笨拙,我正在尽我所能。
背后的想法是拥有一个包含所有相关详细信息的 Excel 表格,并根据此表格发送包含相应相关内容的电子邮件。
电子邮件以 strbody = Cells(cell.Row, "A").Value & Cells(cell.Row, "B").Value _
开头这里的 cell.row A 是问候语(Dear Sir 或 Dear Madam),cell.row B 是人名。
如果我运行代码,一切正常,但该代码行的字体被弄乱了。它以新罗马时代显示,但我希望它具有 arial 大小: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
【问题讨论】:
-
你为什么不改变单元格中的字体而不是使用HTML标签?
-
这就是我试图做的(在 Excel 和 Outlook 中),但它不起作用。