首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Outlook VBA宏忽略选定文本块中的拼写错误

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

Stack Overflow用户
提问于 2018-04-12 18:49:51
回答 3查看 1.5K关注 0票数 1

在撰写一封包含大量编程术语的电子邮件时,我希望我的一般拼写错误能以红色的方式显示出来,但当许多特殊的单词也显示为错误时,它会变得很烦人。我可以运行通过拼写检查,并告诉它‘忽略所有’的每一个拼写事件,和红色的混乱将消失。然后,当我继续撰写消息时,拼写检查继续在新编辑上工作。

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

我的想法来自于免费的微软OneNote Onetastic外接程序“无拼写检查”宏。如果能在Outlook中做到这一点,那就太好了。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-04-16 20:30:02

从BigBen开始,我就能回答这个问题。我给了他支票,但这是我想回答我问题的函数。(编辑:现在我看到了这个响应是如何排列的,所以我检查了这个答案。)

代码语言:javascript
运行
复制
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窗口)时打开“快速访问工具栏”。跟随下图中的箭头。

票数 1
EN

Stack Overflow用户

发布于 2018-04-12 21:25:27

相对于选定的文本,清除整个消息正文似乎更容易(至少也可能);希望这会给您一些启发。

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

代码语言:javascript
运行
复制
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
票数 1
EN

Stack Overflow用户

发布于 2018-04-25 13:06:09

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

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

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

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

代码语言:javascript
运行
复制
oDoc.Application.Options.CheckGrammarWithSpelling = Not oDoc.Application.Options.CheckGrammarWithSpelling
oDoc.Application.Options.CheckSpellingAsYouType = Not oDoc.Application.Options.CheckSpellingAsYouType
oDoc.Application.ScreenRefresh

以下是完整宏

代码语言:javascript
运行
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49803910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档