You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Outlook VBA宏开发需求:批量忽略选中文本的拼写错误

Batch Ignore All Spelling Errors in Selected Outlook Text (VBA Macro)

I feel your pain—dealing with false-positive spelling flags for technical jargon in Outlook emails is such a tedious chore when you have to manually click "Ignore All" for every single term. This macro automates the process by targeting only the spelling errors in your selected text and applying "Ignore All" to each unique word in one go.

The Macro Code

Sub BatchIgnoreSelectedSpellingErrors()
    Dim objMail As MailItem
    Dim objWordDoc As Word.Document
    Dim objSelection As Word.Selection
    Dim objSpellingError As Word.SpellingError
    Dim ignoredWords As Collection
    Dim word As Variant
    
    ' Check if an email is open and text is selected
    On Error Resume Next
    Set objMail = ActiveInspector.CurrentItem
    On Error GoTo 0
    
    If objMail Is Nothing Then
        MsgBox "Please open an email and select some text first!", vbExclamation
        Exit Sub
    End If
    
    ' Access the email's Word editor and selected text range
    Set objWordDoc = objMail.GetInspector.WordEditor
    Set objSelection = objWordDoc.Application.Selection
    
    If objSelection Is Nothing Or objSelection.Text = "" Then
        MsgBox "No text selected!", vbExclamation
        Exit Sub
    End If
    
    ' Track unique words to avoid redundant ignore calls
    Set ignoredWords = New Collection
    
    ' Collect all unique spelling errors in the selected range
    On Error Resume Next ' Skip duplicates in the collection
    For Each objSpellingError In objSelection.Range.SpellingErrors
        ignoredWords.Add objSpellingError.Text, Key:=UCase(objSpellingError.Text)
    Next objSpellingError
    On Error GoTo 0
    
    ' Apply "Ignore All" to each unique word globally
    For Each word In ignoredWords
        objWordDoc.Application.CheckSpelling IgnoreAll:=True, Word:=word
    Next word
    
    MsgBox "Successfully ignored all unique spelling errors in selected text!", vbInformation
    
    ' Clean up objects
    Set objSpellingError = Nothing
    Set objSelection = Nothing
    Set objWordDoc = Nothing
    Set objMail = Nothing
    Set ignoredWords = Nothing
End Sub

How to Use the Macro

  1. Open the VBA Editor: In Outlook, press Alt + F11.
  2. Add a Module: In the Project Explorer (left pane), right-click your Outlook project (usually VBAProject.OTM) > Insert > Module.
  3. Paste the Code: Copy the code above and paste it into the blank module.
  4. Save and Enable Macros: Save the project with Ctrl + S. You’ll need to enable macros in Outlook’s Trust Center (File > Options > Trust Center > Trust Center Settings > Macro Settings) to run it.
  5. Run the Macro: Open an email, select the text with spelling errors, press Alt + F8, select BatchIgnoreSelectedSpellingErrors, then click Run.

How It Works

  • Validation: First, it checks if an email is open and text is selected to avoid errors.
  • Word Editor Access: Outlook uses Word’s engine for email editing, so we tap into that to access spelling error data.
  • Unique Word Collection: We collect only unique misspelled words to skip redundant "Ignore All" actions (no need to ignore the same term 10 times).
  • Global Ignore: The macro applies "Ignore All" to each unique word, which adds them to Outlook’s global ignore list—so those terms won’t be flagged in future emails either.

Notes

  • This affects Outlook’s global spelling settings, so ignored words won’t appear as errors in any future emails or documents using Outlook’s checker.
  • If you get a "reference missing" error, go to Tools > References in the VBA Editor and check the box for Microsoft Word xx.x Object Library (xx.x matches your Office version, e.g., 16.0 for Office 365/2019).

内容的提问来源于stack exchange,提问作者Ben

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 10:02:58