我已经在PowerPoint VBA中成功编程了这个,但是无法使它在Outlook上运行。
我尝试了几次尝试“替换”,“如果” - 循环但没有成功。非常感谢让我走上正轨。
以下代码转换正文的颜色,但不区分粗体字。有什么想法吗?
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
答案 0 :(得分:0)
首先,我建议从MSDN中的Getting Started with VBA in Outlook 2010文章开始。
您可以使用Outlook项目的HTMLBody属性来获取邮件正文的HTML内容,或使用Word对象模型完成工作。 Inspector类的WordEditor属性从WOM(Word对象模型)返回Document类的实例。有关详细信息,请参阅Chapter 17: Working with Item Bodies。