Click here to Skip to main content
11,790,366 members (61,743 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET Word Office-Interop , +
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
Edited 7-Apr-13 23:20pm
Maciej Los at 6-Apr-13 18:17pm
Please, post the body of DoAccentuate function.
Have you seen this:[^]
johhosoe48 at 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 at 7-Apr-13 7:15am
I got a headeach for scrolling down here, please just post the relevant code and not everything.
ThePhantomUpvoter at 7-Apr-13 7:39am
Agreed. I am not going to wade through all of those If/ElseIf statements.
johhosoe48 at 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
0 OriginalGriff 315
1 ppolymorphe 219
2 Richard MacCutchan 158
3 Jochen Arndt 95
4 Maciej Los 90
0 OriginalGriff 1,114
1 Maciej Los 825
2 KrunalRohit 686
3 CPallini 611
4 ppolymorphe 610

Advertise | Privacy | Mobile
Web02 | 2.8.1509028.1 | Last Updated 8 Apr 2013
Copyright © CodeProject, 1999-2015
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