Word文档中每个单词的重音更好的方法? [英] better method for accenting every word in Word document?

查看:233
本文介绍了Word文档中每个单词的重音更好的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手,但我正在尝试将现有脚本改编为MS Word 2010/2013插件,以为打开的文档中的每个拉丁词添加正确的重音符号.

I am new to programming, but I am trying to adapt an existing script as a MS Word 2010/2013 addin to add correct stress accentuation to every Latin word in an open document.

对于我以字符串形式发送的所有未重音拉丁词,脚本"DoAccentuate"返回一个重音词.我只需要帮助就可以更好地遍历所有单词,然后在到达最后一个单词时停止循环.我当前的方法有点愚蠢……我在文档末尾插入一个无意义的单词,然后循环播放,直到选中并强调了该单词为止.

The script "DoAccentuate" returns an accented word for any unaccented Latin word I send it as a string. I just need help doing a better job of looping through all the words, and then stopping the loop when the last word is reached. My current method is a bit goofy...I insert a nonesense word at the end of the document and then loop until it gets selected and accented.

也许有一种更好或更有效的方法来处理整件事.

Perhaps there's a better or more efficient way to go about the whole thing.

    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

推荐答案

好吧,我真的不知道它是否更有效,但是您可以使用 document.Content range.Words 集合以检查主要故事范围内的所有单词

Well, I don't realy know if its more efficient way but you could use document.Content and range.Words collection to check all words in main story range

    document = Globals.ThisAddIn.Application.ActiveDocument

    Dim range As Word.Range
    range = document.Content

    Dim current As Integer
    current = 0

    Dim words As Word.Words
    words = range.Words

    Dim word As Word.Range

    Do
        current = current + 1
        If current < words.Count Then
            word = words(current)
            If word.Text.EndsWith(" ") Then
                word.Text = word.Text.Trim() + "'s "
                'replace the selected word that has been found with its accented counterpart
                'mySelection.Text = Accentuate.Accentuate.DoAccentuate(mySelection.Text)
            Else
                word.Text = word.Text.Trim() + "'s"
            End If
        End If
    Loop Until current = words.Count

这篇关于Word文档中每个单词的重音更好的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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