我是編程新手,但我正在嘗試將現有腳本作爲MS Word 2010/2013插件,以便在打開的文檔中爲每個拉丁文單詞添加正確的重音強調。強調Word文檔中每個單詞的更好方法?
腳本「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
這是否需要支持文檔中的所有故事範圍?目前,這在腳註,腳註和尾註中不起作用;它只會在主要的文字故事中起作用。 – JohnZaj 2013-04-07 21:59:51
@jJack,它只需要在正文中工作。謝謝! – johhoso 2013-04-08 08:41:31