Click here to Skip to main content
13,086,120 members (85,294 online)
Rate this:
Please Sign up or sign in to vote.
I need to add correct stress accents to every word in a Word document. I have a script called "DoAccentuate" which determines the correct accentuation for any word that is input. However, I don't know how to capture the currently selected found word, process it with my DoAccentuate script, and replace that same word with the result (without effecting the formatting of the text in Word). This is what I tried.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim document As Word.Document
        document = Globals.ThisAddIn.Application.ActiveDocument
        Dim FindObject As Word.Find = document.Application.Selection.Find
        With FindObject
            .Text = "<*>"
            .MatchWildcards = True
            .Replacement.Text = Accentuate.Accentuate.DoAccentuate(document.Application.Selection.Text)
        End With
    End Sub

The "DoAccentuate" function comes from an open source Latin program; the function returns a stress accented word as a string (based on some complex patterns) for any Latin word sent to is as a string. For sake of argument, imagine "DoAccentuate" works like this an simply tacks on a letter at the end of the string:
Public Class Accentuate
    Shared Current_Word As String
    Public Shared Function DoAccentuate(ByVal s As String) As String
       Dim Accented_word As String
       Current_word = s
       Accented_word = Current_word & "ǽ"
       DoAccentuate = Accented_word
    End Function
End Class
Posted 5-Apr-13 21:01pm
Updated 7-Apr-13 23:20pm
Maciej Los 6-Apr-13 18:17pm
Please, post the body of DoAccentuate function.
Have you seen this:[^]
johhosoe48 7-Apr-13 7:18am
Thanks for the link; it seems "document.Application.Selection.Text" is the wrong thing for me to send to the DoAccentuate function...what I want to send is the string representing the word which the MSWord wildcard search "<*>" selects.

I am wanting to automatically accent all the words in the document...not having to manually select an individual word.
Kenneth Haugland 7-Apr-13 7:15am
I got a headeach for scrolling down here, please just post the relevant code and not everything.
ThePhantomUpvoter 7-Apr-13 7:39am
Agreed. I am not going to wade through all of those If/ElseIf statements.
johhosoe48 8-Apr-13 5:25am
Sorry about that. I shortend the post.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 8 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100