Visual Basic for MS Word代码不适用于日语 [英] Visual Basic for MS Word code not working for Japanese

查看:140
本文介绍了Visual Basic for MS Word代码不适用于日语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下VB代码(由macropod编写,请参见



我在做什么错了?日语的基本命令是否有所不同?如何修改脚本以获得预期的结果?

解决方案

至少一个错误出现为GrammaticalError,而不是SpellingError。



您可以循环浏览例如,使用与您已经拥有的代码类似的方式来显示GrammaticalErrors。



例如。

 对于ActiveDocument.Range.GrammaticalErrors 
'每个GrammaticalError只是一个单词范围,
'范围覆盖的确切范围并不明显。从您的示例
判断,范围覆盖了句子。
’所以您在这里需要做什么。此示例仅突出显示每个Rng
Rng.HighlightColorIndex = wdYellow
End

有在Word对象模型中,只有两种ProofreadingError类型:wdGrammaticalError和wdSpellingError。


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?

解决方案

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.

这篇关于Visual Basic for MS Word代码不适用于日语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆