Click here to Skip to main content
Rate this: bad
good
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
            .ClearFormatting()
            .Text = "<*>"
            .MatchWildcards = True
            .Replacement.ClearFormatting()
            .Replacement.Text = Accentuate.Accentuate.DoAccentuate(document.Application.Selection.Text)
            .Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
 
        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 22:01pm
Edited 8-Apr-13 0:20am
v3
Comments
Maciej Los at 6-Apr-13 18:17pm
   
Please, post the body of DoAccentuate function.
Have you seen this: http://msdn.microsoft.com/en-us/library/office/aa211953%28v=office.11%29.aspx[^]
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 410
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 264
3 BillWoodruff 235
4 CPallini 195
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 8 Apr 2013
Copyright © CodeProject, 1999-2014
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