VBA - in Word, check if selection contains specified character string -


i have word document multiple lines of text. want determine of lines (or paragraphs if longer line) contains string " / " , delete lines don't have one.

this example of i've been trying achieve. if statement part doesn't work @ present i've been having trouble working out solution.

selection.wholestory nlines = selection.range.computestatistics(statistic:=wdstatisticparagraphs) selection.homekey unit:=wdstory while startnumber2 < nlines startnumber2 = startnumber2 + 1 selection.homekey unit:=wdline selection.movedown unit:=wdparagraph, count:=1, extend:=wdextend if selection.text = " / " selection.movedown unit:=wdline, count:=1 else: selection.delete unit:=wdcharacter, count:=1 end if loop 

this example of text it'll checking. need delete 2 & 4 , leave 1 & 3:

  1. back in black / acdc (3:54) --
  2. tonight (2:44) --
  3. lucy in sky diamonds / beatles (4:22) --
  4. random song name (3:33) --

any appreciated.

thanks comintern. thought there simple way , instr did job.

selection.wholestory nlines = selection.range.computestatistics(statistic:=wdstatisticparagraphs)  selection.homekey unit:=wdstory while startnumber2 < nlines startnumber2 = startnumber2 + 1 selection.homekey unit:=wdline selection.movedown unit:=wdparagraph, count:=1, extend:=wdextend if instr(selection, " / ") > 0 selection.movedown unit:=wdline, count:=1 else: selection.delete unit:=wdcharacter, count:=1 end if loop 

Popular posts from this blog