VBA:在 Word 中的拼写错误旁边编写拼写建议 [英] VBA: Writing spelling suggestions next to spelling errors in Word
问题描述
在 MS Word(Office for Mac 2016,版本 15.31)中,我想通过标记拼写错误并在每个拼写错误的单词旁边写下第一个拼写建议来丰富文档:例如,如果文本说
In MS Word (Office for Mac 2016, version 15.31) I would like to enrich a document by marking spelling errors and by writing the first spelling suggestion next to each misspelled word: for example if the text says
我想丰富
我需要的结果是
我[wuld][would]想丰富
我知道
iErrorCnt=Doc.This.SpellingErrors.Count
For J=1 to iErrorCnt
Selection.TypeText Text:=DocThis.SpellingErrors(J)
Next J
会检查所有拼写错误,我知道
will go through all spelling errors, and I know that
ActiveDocument.Words(1).GetSpellingSuggestions.Item(1).Name
允许获取给定单词的第一个拼写建议.但是,我如何将拼写错误的单词和拼写建议联系起来(因为拼写建议适用于单词并且单词按整数索引)以及如何将它们都标记在文档中?
allows to obtain the first spelling suggestion for a given word. But how do I link the misspelled word and the spelling suggestion (since the spelling suggestion is applied to words and words are indexed by integers) and how do I get them both marked in the document?
推荐答案
尝试:
Sub SpellCheck()
Dim Rng As Range, oSuggestions As Variant
For Each Rng In ActiveDocument.Range.SpellingErrors
With Rng
If .GetSpellingSuggestions.Count > 0 Then
Set oSuggestions = .GetSpellingSuggestions
.Text = "[" & .Text & "][" & oSuggestions(1) & "]"
Else
.Text = "[" & .Text & "][]"
End If
End With
Next
End Sub
这篇关于VBA:在 Word 中的拼写错误旁边编写拼写建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!