私はプログラミングに慣れていませんが、既存のスクリプトを MS Word 2010/2013 アドインとして適応させて、開いているドキュメント内のすべてのラテン語の単語に正しい強勢アクセントを追加しようとしています。
スクリプト "DoAccentuate" は、文字列として送信したアクセントのないラテン語の単語に対してアクセント付きの単語を返します。すべての単語をループして、最後の単語に到達したときにループを停止するというより良い仕事をする助けが必要です。私の現在の方法は少しばかげています...ドキュメントの最後に無意味な単語を挿入し、それが選択されてアクセントが付くまでループします。
おそらく、全体を処理するためのより良い、またはより効率的な方法があります。
Public Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim document As Word.Document
document = Globals.ThisAddIn.Application.ActiveDocument
Dim mySelection = document.Application.Selection
'make sure cursor is at start of document
document.Application.Selection.HomeKey(Unit:=Microsoft.Office.Interop.Word.WdUnits.wdStory)
'insert fake word at end to stop the loop
Dim range As Word.Range
range = document.Range()
range.InsertAfter(" documentendatoris")
Do
'use MS Word's wildcard to select the first individual word as trimmed string
mySelection.Find.Text = "<*>"
mySelection.Find.MatchWildcards = True
mySelection.Find.Execute()
'replace the selected word that has been found with its accented counterpart
mySelection.Text = Accentuate.Accentuate.DoAccentuate(mySelection.Text)
Loop Until mySelection.Text = "documentendatóris"
End Sub