Visual Basic for MS Word code not working for Japanese

我只是一个虾纸丫 提交于 2020-04-30 06:34:43

问题


I'm using the following VB code (authored by macropod, see this stackoverflow question) inside MS Word (Word for Mac v16.16.21) to mark errors and insert the first spell checker suggestion inside a 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

For English text it works fine: This is some very important dokument becomes This is some very important [dokument][document].

But it doesn't work for Japanese: in the following sentence それからバートわチャーリイこのかーどになにが見えるかといった。 there are two errors, the macro does nothing (even though Word marks the errors visually which means that the internal spell checker is aware of the errors:

What am I doing wrong? Are the basic commands different for Japanese? How should I modify my script to get the expected result?


回答1:


At least one of the errors comes up as a GrammaticalError, not a SpellingError here.

You can cycle through the GrammaticalErrors in a similar way to the code you already have, but there is no equivalent of the GetSpellingErrors method.

e.g. you can do

For Each Rng in ActiveDocument.Range.GrammaticalErrors
  ' Each GrammaticalError is just a Word Range, 
  ' It is not obvious exactly what the range "covers". Judging from your example
  ' the range "covers" the sentence.
  ' So do whatever you need here. This example just highlights each Rng
  Rng.HighlightColorIndex = wdYellow
End

There are only two types of ProofreadingError in the Word Object Model - wdGrammaticalError and wdSpellingError.



来源:https://stackoverflow.com/questions/61291205/visual-basic-for-ms-word-code-not-working-for-japanese

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!