繁体   English   中英

VBA:在 Word 中的拼写错误旁边编写拼写建议

[英]VBA: Writing spelling suggestions next to spelling errors in Word

在 MS Word(Office for Mac 2016,版本 15.31)中,我想通过标记拼写错误并在每个拼错的单词旁边写下第一个拼写建议来丰富文档:例如,如果文本显示

我想丰富

我需要的结果是

我[wuld][would]想丰富

我知道

iErrorCnt=Doc.This.SpellingErrors.Count
For J=1 to iErrorCnt
    Selection.TypeText Text:=DocThis.SpellingErrors(J)
Next J

会检查所有拼写错误,我知道

ActiveDocument.Words(1).GetSpellingSuggestions.Item(1).Name

允许获取给定单词的第一个拼写建议。 但是如何将拼写错误的单词和拼写建议联系起来(因为拼写建议适用于单词并且单词按整数索引)以及如何将它们都标记在文档中?

尝试:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM