1

When composing an email that contains a lot of programming terms I want my general spelling errors to show up with a red squiggle but it gets annoying when a lot of special words also show as errors. I can run through the spell check and tell it to 'Ignore All' for each spelling incident and the red squiggles will go away. Then as I continue composing the message the spell check continues to work on new edits.

What I'd like to do is create a VBA macro that will do this for me in the selected text or the entire message body (I don't have a preference). I'm an experienced Access VBA developer but not too familiar with the Spell Check object model in Outlook.

My idea for this came from the free Microsoft OneNote Onetastic add-in and the "No Spell Check" macro. It would be great to be able to do this in Outlook.

Ben
  • 1,168
  • 13
  • 45

3 Answers3

1

It seems easier (and at least possible) to clear the entire message body as opposed to selected text; this should hopefully give you some inspiration.

Note that, assuming you already have spelling errors, the message body is not immediately cleared with ShowSpellingErrors = False. Toggling the language is a quick hack, but was straightforward and simple. More ideas 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
  • 46,229
  • 7
  • 24
  • 40
  • Thanks for the idea and the code for pointing to the WordEditor. After your code runs, spell checking no longer works for new edits. From another post I discovered that oDoc.SpellingChecked = True will clear the red squiggles of existing text but still mark new edits. I updated my question with a completed function but gave you the point for getting me in the right direction. – Ben Apr 16 '18 at 20:18
  • Sounds like exactly what you needed, I was unaware of SpellingChecked. Thanks. – BigBen Apr 16 '18 at 20:22
1

With a kick start from BigBen I was able to answer this question. I gave him the check mark but this is the function I think answers my question. (Edit: now that I see how this response is laid out I checked this answer.)

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

If you want to add this function to your message toolbar, open the Quick Access Toolbar when you have a message window open (not the main Outlook window). Follow the arrows in the image below.

Add quick access button to toolbar

enter image description here

Ben
  • 1,168
  • 13
  • 45
1

Thank you for your answer, this has helped me alot

Another option is to toggle the DISPLAY of checking of gram/spelling as you type options

below is just 3 lines different to your answer, 3rd line refreshes the the word 'application' (editor).

I use these 3 lines in a macro button within Word itself

oDoc.Application.Options.CheckGrammarWithSpelling = Not oDoc.Application.Options.CheckGrammarWithSpelling
oDoc.Application.Options.CheckSpellingAsYouType = Not oDoc.Application.Options.CheckSpellingAsYouType
oDoc.Application.ScreenRefresh

full macro below

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
rokk krinn
  • 11
  • 1
  • I'm glad you got some inspiration from this. If you toggle the application options, won't that apply to all messages? If you turn off the checking you'll never see spell check indicators until the next time this runs. I typically like spell checking indicators and I'm afraid I would forget to turn it back on and send out emils with speling erorrs. – Ben Apr 27 '18 at 13:25