首页 > 解决方案 > 如何在 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粗体文本)。

标签: excelvbaemailoutlook

解决方案


使用.HTMLBody代替.Body

然后你可以使用 HTML - 改变你的vbNewLineto<br>并使用<b> text here </b>来使事情变得粗体。


推荐阅读