【问题标题】:Outlook VBA macro to Ignore Spelling Errors in Selected Block of TextOutlook VBA 宏忽略所选文本块中的拼写错误
【发布时间】:2018-09-23 00:59:09
【问题描述】:

在撰写包含大量编程术语的电子邮件时,我希望我的一般拼写错误以红色曲线显示,但当许多特殊单词也显示为错误时,它会变得很烦人。我可以通过拼写检查并告诉它为每个拼写事件“全部忽略”,红色的曲线就会消失。然后,当我继续撰写邮件时,拼写检查会继续处理新的编辑。

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

我对此的想法来自免费的 Microsoft OneNote Onetastic add-in"No Spell Check" macro。如果能够在 Outlook 中执行此操作,那就太好了。

【问题讨论】:

    标签: vba outlook spell-checking


    【解决方案1】:

    从 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
    

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

    【讨论】:

      【解决方案2】:

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

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

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

      我在 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
      

      【讨论】:

      • 很高兴您从中获得了一些灵感。如果您切换应用程序选项,那不是适用于所有消息吗?如果您关闭检查,则在下次运行之前,您将永远不会看到拼写检查指示符。我通常喜欢拼写检查指示器,我担心我会忘记重新打开它并发送带有拼写错误的 emils。
      【解决方案3】:

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

      请注意,假设您已经有拼写错误,邮件正文不会立即使用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
      

      【讨论】:

      • 感谢您的想法和指向 WordEditor 的代码。代码运行后,拼写检查不再适用于新的编辑。从另一篇文章中,我发现 oDoc.SpellingChecked = True 会清除现有文本的红色曲线,但仍会标记新的编辑。我用一个完整的函数更新了我的问题,但给了你一点让我朝着正确的方向前进。
      • 听起来正是您所需要的,我不知道 SpellingChecked。谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-29
      • 1970-01-01
      • 2013-07-02
      • 1970-01-01
      • 1970-01-01
      • 2020-07-07
      相关资源
      最近更新 更多