我是编程新手,但我正在尝试将现有脚本改编为 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