在我所有的 Outlook 邮件中查找并以斜体形式放置单词列表(在 a.txt 文件中列出)
Find and put in italic a list of words (that are listed in a.txt file) in all my Outlook message
我正在尝试在我的所有 Outlook 邮件中查找并以斜体显示单词列表(在 .txt 文件中列出)。
我在 Outlook 中尝试了一个 Word VBA 宏(找到了 here)。
在 Word 中有效。
在 Outlook 中我得到
Run-time error 424, Object Required.
Sub ChangeWordColorsFile()
Dim sFile As String
Dim sTemp As String
sFile = "C:\Users\me\Desktop\List words.txt"
Open sFile For Input As 1
While Not EOF(1)
Line Input #1, sTemp
sTemp = Trim(sTemp)
If sTemp > "" Then
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Italic = True
With Selection.Find
.Text = sTemp
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End If
Wend
Close #1
End Sub
要在 Outlook 上使用它,请参见下面的示例
Option Explicit
Public Sub Example()
Dim sFile As String
Dim sTemp As String
Dim Inspector As Outlook.Inspector
Dim wdDoc As Word.Document
Dim Selection As Word.Selection
Set Inspector = Application.ActiveInspector()
Set wdDoc = Inspector.WordEditor
Set Selection = wdDoc.Application.Selection
sFile = "D:\Temp\words.txt"
Open sFile For Input As 1
While Not EOF(1)
Line Input #1, sTemp
sTemp = Trim(sTemp)
If sTemp > "" Then
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Italic = True
With Selection.Find
.Text = sTemp
.Replacement.Text = ""
.Forward = True
.wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End If
Wend
Close #1
End Sub
上测试的代码
我正在尝试在我的所有 Outlook 邮件中查找并以斜体显示单词列表(在 .txt 文件中列出)。
我在 Outlook 中尝试了一个 Word VBA 宏(找到了 here)。
在 Word 中有效。
在 Outlook 中我得到
Run-time error 424, Object Required.
Sub ChangeWordColorsFile()
Dim sFile As String
Dim sTemp As String
sFile = "C:\Users\me\Desktop\List words.txt"
Open sFile For Input As 1
While Not EOF(1)
Line Input #1, sTemp
sTemp = Trim(sTemp)
If sTemp > "" Then
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Italic = True
With Selection.Find
.Text = sTemp
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End If
Wend
Close #1
End Sub
要在 Outlook 上使用它,请参见下面的示例
Option Explicit
Public Sub Example()
Dim sFile As String
Dim sTemp As String
Dim Inspector As Outlook.Inspector
Dim wdDoc As Word.Document
Dim Selection As Word.Selection
Set Inspector = Application.ActiveInspector()
Set wdDoc = Inspector.WordEditor
Set Selection = wdDoc.Application.Selection
sFile = "D:\Temp\words.txt"
Open sFile For Input As 1
While Not EOF(1)
Line Input #1, sTemp
sTemp = Trim(sTemp)
If sTemp > "" Then
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Italic = True
With Selection.Find
.Text = sTemp
.Replacement.Text = ""
.Forward = True
.wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End If
Wend
Close #1
End Sub