ms word - Find text and format -


i have recorded macro in word 2007 finds word, moves cursor 2 lines up, inserts 3 '***', highlights line. works on first instance of found word. struggling repeat throughout document instances of word want find.

this output recorded macro. need actions repeated each instance of "b,".

 sub highlightnewitems() ' ' highlightnewitems macro ' '     selection.find.clearformatting     selection.find         .text = "b,"         .replacement.text = ""         .forward = true         .wrap = wdfindcontinue         .format = false         .matchcase = true         .matchwholeword = false         .matchwildcards = false         .matchsoundslike = false         .matchallwordforms = false     end     selection.find.execute     selection.moveup unit:=wdline, count:=2     selection.moveleft unit:=wdword, count:=1     selection.typetext text:="***"     selection.typeparagraph     selection.endkey unit:=wdline, extend:=wdextend     options.defaulthighlightcolorindex = wdred     selection.range.highlightcolorindex = wdred     selection.moveright unit:=wdcharacter, count:=1 end sub 

try putting following construct within with.selection.find

do while .execute   '(logic want apply after finding string) loop 

in case, code like

sub highlightnewitems() ' ' highlightnewitems macro ' '     selection.find.clearformatting     selection.find         .text = "b,"         .replacement.text = ""         .forward = true         .wrap = wdfindcontinue         .format = false         .matchcase = true         .matchwholeword = false         .matchwildcards = false         .matchsoundslike = false         .matchallwordforms = false        while .execute         selection.moveup unit:=wdline, count:=2         selection.moveleft unit:=wdword, count:=1         selection.typetext text:="***"         selection.typeparagraph         selection.endkey unit:=wdline, extend:=wdextend         options.defaulthighlightcolorindex = wdred         selection.range.highlightcolorindex = wdred         selection.moveright unit:=wdcharacter, count:=1       loop       end  end sub 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -