excel - 如何在 VBA 中将动态 Excel 单元格中的 Outlook 文本加粗?
问题描述
我想将正文中的动态单元格格式化为粗体。
我希望电子邮件正文看起来像这样:
亲爱的用户,
以下请求在 I8.1 检查资源可用性中:
测试项目
下面的估计工作量在请求的 ROM 中调用(以小时为单位): 10和持续时间(以工作日为单位): 2 你有我可以为调用的工作量投入的命名资源吗?请尽快给我更新
感谢你并致以真诚的问候,
团队。
此代码有效,但我找不到加粗所需值的方法。
Sub Sendmail()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("D").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "E").Value) <> "0" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Resources awaiting assignment"
.Body = "Dear " & Cells(cell.Row, "C").Value _
& ", " _
& vbNewLine & vbNewLine & _
"The following request is in I8.1 Check Resource Availability: " _
& vbNewLine & vbNewLine & _
Cells(cell.Row, "A").Value _
& vbNewLine & vbNewLine & _
"The estimated effort below is called out in the request's ROM (in hours): " & Cells(cell.Row, "E").Value _
& _
" and duration (in business days): " & Cells(cell.Row, "F").Value _
& vbNewLine & vbNewLine & _
"Do you have a named resource I can put in for the effort called out? Please provide me with an update at the earliest" _
& vbNewLine & vbNewLine & _
"Thank you and best regards, " & vbNewLine & _
"Team."
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
我查看了一些关于在 VBA 中格式化电子邮件正文的帖子(例如,如何格式化电子邮件正文?、使用 VBA 格式化电子邮件正文或 使用 VBA粗体文本)。
解决方案
使用.HTMLBody
代替.Body
然后你可以使用 HTML - 改变你的vbNewLine
to<br>
并使用<b> text here </b>
来使事情变得粗体。
推荐阅读
- ios - 单击tableview标题按钮时如何将tableviewcell内的collectionview中的数据显示到另一个视图控制器
- r - R预测包中的动态回归
- python - 为什么我的请求返回一个空列表?
- docker - 在离线 Centos 服务器上安装 docker
- systemd - systemd:延迟发送 SIGTERM 两次,*然后*发送 SIGKILL?
- reactjs - 更新上下文时避免运行效果挂钩
- android - 无法解析配置“:app:debugRuntimeClasspath”的所有文件。对于谷歌广告
- pytorch - pytorch 中的一种热编码
- scanf - 为什么 scanf 在代码块 IDE 中无法正常工作
- python - 值错误。视图“users.views.register”没有返回 HttpResponse 对象。它返回 None 而不是