用于忽略所选文本块中的拼写错误的 Outlook VBA 宏
Outlook VBA macro to Ignore Spelling Errors in Selected Block of Text
在撰写包含大量编程术语的电子邮件时,我希望我的一般拼写错误显示为红色波浪线,但当很多特殊词也显示为错误时,这会让人很烦。我可以 运行 通过拼写检查并告诉它 'Ignore All' 每个拼写事件 并且红色波浪线会消失。然后,当我继续撰写邮件时,拼写检查会继续对新的编辑工作。
我想做的是创建一个 VBA 宏,它将在选定的文本或整个邮件正文中为我执行此操作(我没有偏好)。我是一位经验丰富的 Access VBA 开发人员,但不太熟悉 Outlook 中的拼写检查对象模型。
我的想法来自免费的 Microsoft OneNote Onetastic add-in and the "No Spell Check" macro。如果能够在 Outlook 中执行此操作,那就太好了。
与选定的文本相比,清除整个邮件正文似乎更容易(至少可能);希望这会给您一些启发。
请注意,假设您已经有拼写错误,邮件正文不会立即用 ShowSpellingErrors = False
清除。切换语言是一个快速的技巧,但是简单明了。更多想法 here.
Option Explicit
Sub Test()
' Add a reference to the Microsoft Word Object Library for this to compile
Dim oDoc As Word.Document
Dim oMail As Outlook.MailItem
If TypeOf Application.ActiveInspector.CurrentItem Is Outlook.MailItem Then
Set oMail = Application.ActiveInspector.CurrentItem
Else
Exit Sub
End If
Set oDoc = oMail.GetInspector.WordEditor
If Not (oDoc Is Nothing) Then
oDoc.ShowSpellingErrors = False
' Toggling the language forces a recheck of the body, to clear red squiggles
oDoc.Range.LanguageID = wdAfrikaans
oDoc.Range.LanguageID = wdEnglishUS
End If
End Sub
从 BigBen 开始,我能够回答这个问题。我给了他复选标记,但我认为这是回答我问题的功能。 (编辑:既然我看到了这个回复的布局,我检查了这个答案。)
Public Sub **ClearSpellCheckSquiggles**()
' Remove the red squiggles from the current document because they may be distracting
' while composing a message with a lot special words (like code).
' New text added after this runs will still be checked and indicated by red squiggles.
' This assumes that you also have Word installed on your box. If so, you can
' access most of the Word OM from the Outlook VBE *without* referencing Word
' by using the ActiveInspector.WordEditor object.
Dim oDoc As Object ' Word.Document ' Or add a reference to the Microsoft Word Object Library for IntelliSense
Dim oMail As Outlook.MailItem
If TypeOf Application.ActiveInspector.CurrentItem Is Outlook.MailItem Then
Set oMail = Application.ActiveInspector.CurrentItem
Else
Exit Sub
End If
Set oDoc = oMail.GetInspector.WordEditor
If Not (oDoc Is Nothing) Then
' Mark the current document as already spell-checked:
oDoc.SpellingChecked = True
' Mark the current document as already grammar-checked (green squiggles):
oDoc.GrammarChecked = True
End If
End Sub
如果要将此功能添加到邮件工具栏,请在打开邮件 window(不是主 Outlook window)时打开快速访问工具栏。按照下图中的箭头操作。
谢谢你的回答,对我帮助很大
另一个选项是在您键入选项时切换 gram/spelling 检查的显示
下面只有 3 行与您的答案不同,第 3 行刷新了单词 'application'(编辑)。
我在 Word 本身的宏按钮中使用了这 3 行
oDoc.Application.Options.CheckGrammarWithSpelling = Not oDoc.Application.Options.CheckGrammarWithSpelling
oDoc.Application.Options.CheckSpellingAsYouType = Not oDoc.Application.Options.CheckSpellingAsYouType
oDoc.Application.ScreenRefresh
完整宏如下
Public Sub ClearSpellCheckSquiggles()
' Remove the red squiggles from the current document because they may be distracting
' while composing a message with a lot special words (like code).
' New text added after this runs will still be checked and indicated by red squiggles.
' This assumes that you also have Word installed on your box. If so, you can
' access most of the Word OM from the Outlook VBE *without* referencing Word
' by using the ActiveInspector.WordEditor object.
Dim oDoc As Word.Document ' Or add a reference to the Microsoft Word Object Library for IntelliSense
Dim oMail As Outlook.MailItem
If TypeOf Application.ActiveInspector.CurrentItem Is Outlook.MailItem Then
Set oMail = Application.ActiveInspector.CurrentItem
Else
Exit Sub
End If
Set oDoc = oMail.GetInspector.WordEditor
If Not (oDoc Is Nothing) Then
' ' Mark the current document as already spell-checked:
' oDoc.SpellingChecked = True
'
' ' Mark the current document as already grammar-checked (green squiggles):
' oDoc.GrammarChecked = True
oDoc.Application.Options.CheckGrammarWithSpelling = Not oDoc.Application.Options.CheckGrammarWithSpelling
oDoc.Application.Options.CheckSpellingAsYouType = Not oDoc.Application.Options.CheckSpellingAsYouType
oDoc.Application.ScreenRefresh
End If
End Sub
在撰写包含大量编程术语的电子邮件时,我希望我的一般拼写错误显示为红色波浪线,但当很多特殊词也显示为错误时,这会让人很烦。我可以 运行 通过拼写检查并告诉它 'Ignore All' 每个拼写事件 并且红色波浪线会消失。然后,当我继续撰写邮件时,拼写检查会继续对新的编辑工作。
我想做的是创建一个 VBA 宏,它将在选定的文本或整个邮件正文中为我执行此操作(我没有偏好)。我是一位经验丰富的 Access VBA 开发人员,但不太熟悉 Outlook 中的拼写检查对象模型。
我的想法来自免费的 Microsoft OneNote Onetastic add-in and the "No Spell Check" macro。如果能够在 Outlook 中执行此操作,那就太好了。
与选定的文本相比,清除整个邮件正文似乎更容易(至少可能);希望这会给您一些启发。
请注意,假设您已经有拼写错误,邮件正文不会立即用 ShowSpellingErrors = False
清除。切换语言是一个快速的技巧,但是简单明了。更多想法 here.
Option Explicit
Sub Test()
' Add a reference to the Microsoft Word Object Library for this to compile
Dim oDoc As Word.Document
Dim oMail As Outlook.MailItem
If TypeOf Application.ActiveInspector.CurrentItem Is Outlook.MailItem Then
Set oMail = Application.ActiveInspector.CurrentItem
Else
Exit Sub
End If
Set oDoc = oMail.GetInspector.WordEditor
If Not (oDoc Is Nothing) Then
oDoc.ShowSpellingErrors = False
' Toggling the language forces a recheck of the body, to clear red squiggles
oDoc.Range.LanguageID = wdAfrikaans
oDoc.Range.LanguageID = wdEnglishUS
End If
End Sub
从 BigBen 开始,我能够回答这个问题。我给了他复选标记,但我认为这是回答我问题的功能。 (编辑:既然我看到了这个回复的布局,我检查了这个答案。)
Public Sub **ClearSpellCheckSquiggles**()
' Remove the red squiggles from the current document because they may be distracting
' while composing a message with a lot special words (like code).
' New text added after this runs will still be checked and indicated by red squiggles.
' This assumes that you also have Word installed on your box. If so, you can
' access most of the Word OM from the Outlook VBE *without* referencing Word
' by using the ActiveInspector.WordEditor object.
Dim oDoc As Object ' Word.Document ' Or add a reference to the Microsoft Word Object Library for IntelliSense
Dim oMail As Outlook.MailItem
If TypeOf Application.ActiveInspector.CurrentItem Is Outlook.MailItem Then
Set oMail = Application.ActiveInspector.CurrentItem
Else
Exit Sub
End If
Set oDoc = oMail.GetInspector.WordEditor
If Not (oDoc Is Nothing) Then
' Mark the current document as already spell-checked:
oDoc.SpellingChecked = True
' Mark the current document as already grammar-checked (green squiggles):
oDoc.GrammarChecked = True
End If
End Sub
如果要将此功能添加到邮件工具栏,请在打开邮件 window(不是主 Outlook window)时打开快速访问工具栏。按照下图中的箭头操作。
谢谢你的回答,对我帮助很大
另一个选项是在您键入选项时切换 gram/spelling 检查的显示
下面只有 3 行与您的答案不同,第 3 行刷新了单词 'application'(编辑)。
我在 Word 本身的宏按钮中使用了这 3 行
oDoc.Application.Options.CheckGrammarWithSpelling = Not oDoc.Application.Options.CheckGrammarWithSpelling
oDoc.Application.Options.CheckSpellingAsYouType = Not oDoc.Application.Options.CheckSpellingAsYouType
oDoc.Application.ScreenRefresh
完整宏如下
Public Sub ClearSpellCheckSquiggles()
' Remove the red squiggles from the current document because they may be distracting
' while composing a message with a lot special words (like code).
' New text added after this runs will still be checked and indicated by red squiggles.
' This assumes that you also have Word installed on your box. If so, you can
' access most of the Word OM from the Outlook VBE *without* referencing Word
' by using the ActiveInspector.WordEditor object.
Dim oDoc As Word.Document ' Or add a reference to the Microsoft Word Object Library for IntelliSense
Dim oMail As Outlook.MailItem
If TypeOf Application.ActiveInspector.CurrentItem Is Outlook.MailItem Then
Set oMail = Application.ActiveInspector.CurrentItem
Else
Exit Sub
End If
Set oDoc = oMail.GetInspector.WordEditor
If Not (oDoc Is Nothing) Then
' ' Mark the current document as already spell-checked:
' oDoc.SpellingChecked = True
'
' ' Mark the current document as already grammar-checked (green squiggles):
' oDoc.GrammarChecked = True
oDoc.Application.Options.CheckGrammarWithSpelling = Not oDoc.Application.Options.CheckGrammarWithSpelling
oDoc.Application.Options.CheckSpellingAsYouType = Not oDoc.Application.Options.CheckSpellingAsYouType
oDoc.Application.ScreenRefresh
End If
End Sub