[英]VBA: Writing spelling suggestions next to spelling errors in Word
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在 MS Word(Office for Mac 2016,版本 15.31)中,我想通过标记拼写错误并在每个拼错的单词旁边写下第一个拼写建议来丰富文档:例如,如果文本显示
I wuld like to enrich我想丰富
the result I need is我需要的结果是
I [wuld][would] like to enrich我[wuld][would]想丰富
I know that我知道
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?
但是如何将拼写错误的单词和拼写建议联系起来(因为拼写建议适用于单词并且单词按整数索引)以及如何将它们都标记在文档中?
Try:尝试:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.