Generating replacement text from found text for Word addin, using VB.NET and Office-Interop -
i need add correct stress accents every word in microsoft word document. have script called "doaccentuate" determines correct accentuation word input. however, don't know how capture selected found word, process doaccentuate script, , replace same word result (without effecting formatting of text). tried.
private sub button1_click(sender object, e eventargs) handles button1.click dim document word.document document = globals.thisaddin.application.activedocument dim findobject word.find = document.application.selection.find findobject .clearformatting() .text = "<*>" .matchwildcards = true .replacement.clearformatting() .replacement.text = doaccentuate(document.application.selection.text) .execute(replace:=microsoft.office.interop.word.wdreplace.wdreplaceall) end end sub
lets pretend doaccentuate script:
private function doaccentuate(thewordtoaccentuate string) thewordtoaccentuate = thewordtoaccentuate + "`" doaccentuate = thewordtoaccentuate end function given this, find/replace can simple as:
public sub findwordandreplacewithaccentuatedform() dim accentuatedtext string: accentuatedtext = doaccentuate(selection.text) selection.find.text = selection.text selection.find.replacement.text = doaccentuate(selection.text) selection.find.execute replace:=wdreplaceall end sub this should not remove formatting.
i assuming desire solution requires user select word want accentuate, , run macro (since method above assumes ie: .replacement.text = doaccentuate(document.application.selection.text
Comments
Post a Comment