Search code examples
vbaoutlookspell-checking

Outlook VBA macro to Ignore Spelling Errors in Selected Block of Text


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.


Solution

  • 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