您可能知道,自定义词典只是一个包含单词的文本文件,因此请参考 Microsoft Scripting Runtime,并使用:
Dim FSO As New FileSystemObject, FS As TextStream
Dim Code As String, Codes As New Scripting.Dictionary
Dim Paragraph As Paragraph, Word As Range
Set FS = FSO.OpenTextFile("c:\...\cust.dic")
Do Until FS.AtEndOfStream
Code = FS.ReadLine
If Not Codes.Exists(Code) Then Codes.Add Key:=Code, Item:=Nothing
Loop
' Use your own method for enumerating words
For Each Paragraph In ActiveDocument.Paragraphs
Set Word = Paragraph.Range
Word.MoveEnd WdUnits.wdCharacter, -1
If Not Codes.Exists(Word.Text) Then
Word.Font.Underline = wdUnderlineWavy
Word.Font.UnderlineColor = wdColorBlue
Else
Word.Font.Underline = wdUnderlineNone
Word.Font.UnderlineColor = wdColorAutomatic
End If
Next
不理想,因为它破坏了下划线格式,并且不提供建议机制(尽管围绕列表框构建的小表单就足够了)。
不幸的是,最好的解决方案是扩展拼写引擎。