【问题标题】:Programmatically change font properties in email body以编程方式更改电子邮件正文中的字体属性
【发布时间】:2020-06-28 09:07:58
【问题描述】:

我已在 PowerPoint VBA 中成功编程,但无法在 Outlook 上运行。

  1. 我准备好在 Outlook 2013 中发送电子邮件
  2. 我想扫描电子邮件正文中的粗体文本(即粗体字符)并将其颜色更改为红色
  3. (很高兴)从宏中排除签名

我用“Substitute”、“if”循环尝试了几次,但都没有成功。非常感谢您让我走上正轨。


以下代码转换了正文的颜色,但不区分粗体字。有什么想法吗?

Public Sub FormatSelectedText()
    Dim objItem As Object
    Dim objInsp As Outlook.Inspector

    ' Add reference to Word library
    ' in VBA Editor, Tools, References
    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection
    On Error Resume Next

'Reference the current Outlook item
    Set objItem = Application.ActiveInspector.CurrentItem
    If Not objItem Is Nothing Then
        If objItem.Class = olMail Then
            Set objInsp = objItem.GetInspector
            If objInsp.EditorType = olEditorWord Then
                Set objDoc = objInsp.WordEditor
                Set objWord = objDoc.Application
                Set objSel = objWord.Selection


            ' replace the With block with your code
                   With objSel
                   ' Formatting code goes here
                        '.Font.Size = 18
                        If .Font.Bold = True Then
                            .Font.Color = wdColorBlue
                        End If
                        .Font.Color = wdColorRed
                        '.Font.Italic = True
                        '.Font.Name = "Arial"
                   End With

            End If
        End If
    End If

    Set objItem = Nothing
    Set objWord = Nothing
    Set objSel = Nothing
    Set objInsp = Nothing
End Sub

【问题讨论】:

标签: vba outlook outlook-2010


【解决方案1】:

首先,我建议从 MSDN 中的Getting Started with VBA in Outlook 2010 文章开始。

您可以使用 Outlook 项目的HTMLBody 属性来获取邮件正文的 HTML 内容或使用 Word 对象模型来完成工作。 Inspector 类的WordEditor 属性从 WOM(Word 对象模型)返回 Document 类的实例。请参阅Chapter 17: Working with Item Bodies 了解更多信息。

【讨论】:

    猜你喜欢
    • 2015-09-24
    • 2012-07-14
    • 2017-03-14
    • 2021-12-19
    • 1970-01-01
    • 2014-02-01
    • 2020-06-10
    • 1970-01-01
    相关资源
    最近更新 更多