![]() |
#4
|
||||
|
||||
![]()
Maybe something like the following, but there are lots of potential unknowns. e.g. what about multiple occurrences of the string? What if the string is found in the paragraphs being deleted?
Code:
Sub FindString() Const strText As String = "string" Dim orng As Range Dim oPara As Range Set orng = ActiveDocument.Range With orng.Find Do While .Execute(strText) Set oPara = orng.Paragraphs(1).Range 'The paragraph with the string If Not oPara.Start = ActiveDocument.Range.Start Then oPara.Previous.Paragraphs(1).Range.Delete End If If Not oPara.Start = ActiveDocument.Range.Start Then oPara.Previous.Paragraphs(1).Range.Delete End If If Not oPara.End = ActiveDocument.Range.End Then oPara.Next.Paragraphs(1).Range.Delete End If If Not oPara.End = ActiveDocument.Range.End Then oPara.Next.Paragraphs(1).Range.Delete End If Exit Do ' Find only the first occurrence Loop End With lbl_Exit: Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Tags |
word vba |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
boutells | Word | 2 | 08-17-2016 12:18 PM |
Display paragraph of text based on value selected in combo | WordWaza | Word | 0 | 08-09-2013 06:30 AM |
![]() |
Helix86 | Word | 5 | 08-07-2013 10:48 PM |
![]() |
machineworks | Word | 1 | 08-03-2012 08:51 PM |
![]() |
Jamal NUMAN | Word | 2 | 07-12-2011 03:12 AM |