Outlook VBA宏忽略选定文本块中的拼写错误

Outlook VBA宏忽略选定文本块中的拼写错误,vba,outlook,spell-checking,Vba,Outlook,Spell Checking,当撰写一封包含大量编程术语的电子邮件时,我希望我的一般拼写错误显示为红色波浪形,但当许多特殊单词也显示为错误时,这会让人恼火。我可以运行拼写检查,并告诉它对每个拼写事件都“忽略所有”,红色的波形将消失。然后,当我继续撰写消息时,拼写检查将继续进行新的编辑 我想做的是创建一个VBA宏,它将在所选文本或整个邮件正文中为我执行此操作(我没有首选项)。我是一名经验丰富的Access VBA开发人员,但不太熟悉Outlook中的拼写检查对象模型 我的想法来自免费的Microsoft OneNote和。能够

当撰写一封包含大量编程术语的电子邮件时,我希望我的一般拼写错误显示为红色波浪形,但当许多特殊单词也显示为错误时,这会让人恼火。我可以运行拼写检查,并告诉它对每个拼写事件都“忽略所有”,红色的波形将消失。然后,当我继续撰写消息时,拼写检查将继续进行新的编辑

我想做的是创建一个VBA宏,它将在所选文本或整个邮件正文中为我执行此操作(我没有首选项)。我是一名经验丰富的Access VBA开发人员,但不太熟悉Outlook中的拼写检查对象模型

我的想法来自免费的Microsoft OneNote和。能够在Outlook中执行此操作将非常棒。

与选定文本相比,清除整个邮件正文似乎更容易(至少是可能的);希望这能给你一些启发

请注意,假设您已经有拼写错误,消息正文不会立即用
ShowSpellingErrors=False
清除。切换语言是一种快速的技巧,但简单明了。更多的想法


在BigBen的一脚踢开后,我能够回答这个问题。我给了他复选标记,但我认为这是回答我问题的功能。(编辑:现在我看到了这个回答的布局,我检查了这个答案。)

如果要将此功能添加到邮件工具栏,请在打开邮件窗口(而不是Outlook主窗口)时打开快速访问工具栏。按照下图中的箭头进行操作


谢谢你的回答,这对我帮助很大

另一个选项是在键入选项时切换语法/拼写检查的显示

下面是与您的答案不同的3行,第3行刷新“应用程序”(编辑器)一词

我在Word本身的宏按钮中使用这三行

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

感谢您的想法和指向WordEditor的代码。代码运行后,拼写检查不再适用于新编辑。在另一篇文章中,我发现oDoc.SpellingChecked=True将清除现有文本中的红色扭曲,但仍会标记新编辑。我用一个完整的函数更新了我的问题,但给了你让我朝正确方向发展的要点。听起来正是你需要的,我不知道拼写检查。谢谢。我很高兴你从中得到了一些灵感。如果您切换应用程序选项,这不适用于所有邮件吗?如果你关闭检查,你将永远看不到拼写检查指示器,直到下一次运行。我通常喜欢拼写检查指示器,我担心我会忘记重新打开它,并发送带有speling erorrs的emils。
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