Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 12-14-2015, 12:18 AM
gmayor's Avatar
gmayor gmayor is offline How to do task based on paragraph numbering after find Windows 10 How to do task based on paragraph numbering after find Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
 

Tags
word vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to do task based on paragraph numbering after find 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
How to do task based on paragraph numbering after find reset numbering to 1 by paragraph Style Helix86 Word 5 08-07-2013 10:48 PM
How to do task based on paragraph numbering after find Paragraph numbering disappears when using {If machineworks Word 1 08-03-2012 08:51 PM
How to do task based on paragraph numbering after find How to make numbering within a paragraph? Jamal NUMAN Word 2 07-12-2011 03:12 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:36 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft