Vba 以编程方式更改电子邮件正文中的字体属性
我已经成功地在PowerPoint VBA中编程,但未能在Outlook上运行Vba 以编程方式更改电子邮件正文中的字体属性,vba,outlook,outlook-2010,Vba,Outlook,Outlook 2010,我已经成功地在PowerPoint VBA中编程,但未能在Outlook上运行 我准备在Outlook 2013中发送一封电子邮件 我想扫描邮件正文中的粗体文本(即粗体字符),并将其颜色更改为红色 (很高兴有)从宏中排除签名 我尝试了几次使用“替换”、“如果”-循环的尝试,但都没有成功。非常感谢你让我走上正轨 以下代码转换正文的颜色,但不区分粗体字。有什么想法吗 Public Sub FormatSelectedText() Dim objItem As Object Dim
以下代码转换正文的颜色,但不区分粗体字。有什么想法吗
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
首先,我建议从MSDN中的文章开始
您可以使用Outlook items的属性来获取邮件正文的HTML内容,也可以使用Word对象模型来完成作业。Inspector类的属性从WOM(Word对象模型)返回文档类的实例。有关更多信息,请参阅 这里继续讨论[1]: