Word 2010 VBA Macro: loop to end of document -
i have recorded simple macro find word "quantity", go end of line , insert carriage return. need repeat end of document , quit, or else i'll have infinite loop.
the code:
selection.find.clearformatting selection.find .text = "quantity:" .replacement.text = "" .forward = true .wrap = wdfindcontinue .format = false .matchcase = true .matchwholeword = false .matchwildcards = false .matchsoundslike = false .matchallwordforms = false end selection.find.execute selection.endkey unit:=wdline selection.typeparagraph
change code this, note use of wdfindstop.
selection.find.clearformatting selection.find .text = "quantity:" .replacement.text = "" .forward = true .wrap = wdfindstop .format = false .matchcase = true .matchwholeword = false .matchwildcards = false .matchsoundslike = false .matchallwordforms = false end while selection.find.execute = true selection.endkey unit:=wdline selection.typeparagraph loop
if have type of documents can fail on can use selection.start replacing loop this:
dim lastpos long lastpos = -1 while selection.find.execute = true if lastpos > selection.start exit selection.endkey unit:=wdline selection.typeparagraph loop
Comments
Post a Comment