![]() |
|
|
|
#1
|
||||
|
||||
|
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 |
|
#2
|
||||
|
||||
|
My doc have multiple occurrences of string but will never be part of paragraphs being deleted.
The question still remains how to get paragraph numbers of each strings that are found. I want to perform this operation for all the string before deleting the paragraphs. Thanks for reply, as this will surely help. I lost track in between. I will try and get back. |
|
| Tags |
| word vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
multi-level Paragraph numbering
|
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 |
reset numbering to 1 by paragraph Style
|
Helix86 | Word | 5 | 08-07-2013 10:48 PM |
Paragraph numbering disappears when using {If
|
machineworks | Word | 1 | 08-03-2012 08:51 PM |
How to make numbering within a paragraph?
|
Jamal NUMAN | Word | 2 | 07-12-2011 03:12 AM |