[英]Programmatically change font properties in email body
I have been successfully programming this in PowerPoint VBA but haven't been able to make it work on Outlook.我已经在 PowerPoint VBA 中成功地进行了编程,但无法在 Outlook 上运行。
I tried several attempts with "Substitute", "if"-loop but no success.我尝试了几次“替换”、“if”循环但没有成功。 Thanks a lot for putting me on the right track.
非常感谢让我走上正轨。
The following code converts the color of the body but does not discriminate for bold words.以下代码转换正文的颜色,但不区分粗体字。 Any ideas?
有任何想法吗?
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
First of all, I'd suggest starting from the Getting Started with VBA in Outlook 2010 article in MSDN.首先,我建议从 MSDN 中 Outlook 2010中的VBA 入门文章开始。
You can use the HTMLBody property of Outlook items to get the HTML content of the message body or use the Word object model to get the job done.您可以使用 Outlook 项目的HTMLBody属性来获取邮件正文的 HTML 内容或使用 Word 对象模型来完成工作。 The WordEditor property of the Inspector class returns an instance of the Document class from the WOM (Word object model).
Inspector 类的WordEditor属性从 WOM(Word 对象模型)返回 Document 类的实例。 See Chapter 17: Working with Item Bodies for more information.
有关详细信息,请参阅第 17 章:使用项目正文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.