我正在尝试使用 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/