突出显示Outlook 2013(VBA)阅读窗格中的文本
我是VBA的新手,为了实现我的目标,我将一堆代码混合在一起。我试图在Outlook的“阅读器”窗格中突出显示特定文本,因此当您单击特定电子邮件时,阅读器将显示电子邮件正文和突出显示的任何文本,在本例中为“测试”一词 目前,什么都没有发生。但如果我双击电子邮件在新窗口中打开它,阅读面板中它后面的预览现在会正确高亮显示。看起来好像它在打开时触发的事件不是预览,然后更改在不再位于顶部的窗口上生效 以下是我目前拥有的代码:突出显示Outlook 2013(VBA)阅读窗格中的文本,vba,email,outlook,Vba,Email,Outlook,我是VBA的新手,为了实现我的目标,我将一堆代码混合在一起。我试图在Outlook的“阅读器”窗格中突出显示特定文本,因此当您单击特定电子邮件时,阅读器将显示电子邮件正文和突出显示的任何文本,在本例中为“测试”一词 目前,什么都没有发生。但如果我双击电子邮件在新窗口中打开它,阅读面板中它后面的预览现在会正确高亮显示。看起来好像它在打开时触发的事件不是预览,然后更改在不再位于顶部的窗口上生效 以下是我目前拥有的代码: Public WithEvents myItem As Outlook.Mail
Public WithEvents myItem As Outlook.MailItem
Private Sub Application_ItemLoad(ByVal Item As Object)
If Item.Class = olMail Then
Set myItem = Item
End If
End Sub
Private Sub myItem_Open(Cancel As Boolean)
EventsDisable = True
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 hed = msg.GetInspector.WordEditor
Set appWord = hed.Application
Set rng = appWord.Selection
rng.Find.HitHighlight ("Test")
End If
End If
Set appWord = Nothing
Set insp = Nothing
Set rng = Nothing
Set hed = Nothing
Set msg = Nothing
EventsDisable = False
End Sub
不要使用
ActiveInspector
-它与浏览器显示的项目无关。
试试下面的方法
set hed = Application.ActiveExplorer.Selection(1).GetInspector.WordEditor
请记住,如果项目显示在检查器中,并且在活动资源管理器中选择了,则上述更改将仅在检查器中突出显示文本,预览窗格将不受影响。如果希望始终使用预览窗格,则可能需要查看显式公开阅读窗格的对象:
set sExplorer = CreateObject("Redemption.SafeExplorer")
sExplorer.Item = Application.ActiveExplorer
set hed = sExplorer.ReadingPane.WordEditor
Set appWord = hed.Application
Set rng = appWord.Selection
rng.Find.HitHighlight ("Test")