【发布时间】:2020-06-28 09:07:58
【问题描述】:
我已在 PowerPoint VBA 中成功编程,但无法在 Outlook 上运行。
- 我准备好在 Outlook 2013 中发送电子邮件
- 我想扫描电子邮件正文中的粗体文本(即粗体字符)并将其颜色更改为红色
- (很高兴)从宏中排除签名
我用“Substitute”、“if”循环尝试了几次,但都没有成功。非常感谢您让我走上正轨。
以下代码转换了正文的颜色,但不区分粗体字。有什么想法吗?
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
【问题讨论】:
-
此处继续讨论 [1]:stackoverflow.com/questions/31263050/…
标签: vba outlook outlook-2010