vba - 如何从 WordEditor 对象中获取所选文本并更改其颜色?

标签 vba outlook outlook-2010

我正在尝试使用 WordEditor对象修改所选文本的颜色(Outlook VBA),但我无法找到有关如何执行此操作的文档或示例。有任何想法吗?

我不想使用 HTML 编辑器,我需要 WordEditor 的解决方案.

我尝试调试代码并使用 OutlookSpy,但每次进入 WordEditor.Content 时,我的 Outlook 都会卡住并重新启动:(。

在 Windows 7 上使用 Outlook 2010

最佳答案

好的 - 我找到了一些有用的东西。丑陋,但有效:

Sub EmphesizeSelectedText(color As Long)
    Dim msg As Outlook.MailItem
    Dim insp As Outlook.Inspector

    Set insp = Application.ActiveInspector
    If insp.CurrentItem.Class = olMail Then
        Set msg = insp.CurrentItem
        If insp.EditorType = olEditorWord Then

            Set document = msg.GetInspector.WordEditor
            Set rng = document.Application.Selection

            With rng.font
                .Bold = True
                .color = color
            End With
        End If
    End If
    Set insp = Nothing
    Set rng = Nothing
    Set hed = Nothing
    Set msg = Nothing
End Sub

最终我找到了一个引用文献 文字编辑器 返回 Document 目的。从那里开始,我花了 2 个小时浏览 MSDN 非常慢的网络帮助,发现要获得所选文本,我需要上升一级到 Application .
重要提示 - 更改 rng.Style.Font没有做我想做的事,当我开始使用 with rng.font 时,它改变了整个文档我的问题解决了(感谢 Excel 的宏记录能力向我展示了正确的语法)

关于vba - 如何从 WordEditor 对象中获取所选文本并更改其颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4361293/

相关文章:

vba - 如何在 VBA 应用程序中隐藏代码

excel - 两个包含文本但一个包含多个定界符的单元格之间的字符串比较

excel - 遍历所有 Outlook 收件箱,包括共享收件箱错误

html - 有条件地针对 Outlook 2007/2010/2013,但不是 Outlook.com

html - Outlook 2010 忽略字体系列

excel - 从 VBA 打开自定义 View 面板

vba - If 和 Do Until 循环 EXCEL VBA

jquery - 仅 CSS 椭圆(即 "...")折叠和展开

vbscript - 使用多个签名由 GPO 自动生成 Outlook 签名

c# - 将工具提示添加到组框