Selecting word text in a for loop -


i created code search through word document , find word appendix3, , if found, delete , space before (section break in case). subtracts number 3 1 , goes top of loop , searches appendix2 , deletes stuff wanted. loops through 3 times, ending @ appendix1. problem deletes appendix3 stuff. if rerun macro delete appendix2 , appendix2. on on. incrementing selection not appear cleared. suggestions how can modify code loop through , select different text each time?

sub removeappendices() dim integer application.screenupdating = false selection.homekey unit:=wdstory 'cntr = 3 'for = 1 3 i=3 1 step -1     selection.find         .clearformatting         .text = "appendix" & cntr         if selection.find.execute             selection.select             selection.delete             selection                 .endkey unit:=wdstory                 .typebackspace                 .delete             end         end if     end     'cntr = cntr - 1  next end sub 

figured out. needed either go top of page within loop instead of before loop, or had wrap text search during find. updated script looks this:

sub removeappendices() dim integer = 3 1 step -1     'selection.homekey unit:=wdstory 'this work wrap better     selection.find         .wrap = wdfindcontinue         .text = "appendix" &         .matchwholeword = true         .matchcase = true         if selection.find.execute             selection.select             selection.delete             selection                 .endkey unit:=wdstory                 .typebackspace                 .delete             end         end if     end next end sub 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -