ms word - Selection.Expand VBA Do While Loop -
i trying write vba script instances of bolded word "illustration", select entire sentence containing word , see if there image object following bold text.
i hung on part select sentence. (i think necessary because need find end of string , image object. sentence strings like: "illustration of blah blah blah")
my current code looks this:
sub searchspecificboldtext() 'start @ top of document selection.homekey unit:=wdstory dim icount integer icount = 0 ' looking selection.find .clearformatting .text = "illustration" .font.bold = true .forward = true .matchcase = true end ' keep looping once found while selection.find.execute = true icount = icount + 1 msgbox selection.information(wdactiveendpagenumber) msgbox selection.text loop end sub this looping through document , giving me page numbers reference.
when try: .expand unit:=wdsentence inside with selection.find section, method or data member not found.
when try:
do while selection.find.execute = true selection .expand unit:=wdsentence end icount = icount + 1 msgbox selection.information(wdactiveendpagenumber) msgbox selection.text loop i sentence, loop stops working , first instance of "illustration" sentence on , on again.
i have tried placing
with selection .expand unit:=wdsentence end outside of while loop, causes script nothing.
Comments
Post a Comment