Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-09-2015, 05:08 AM
PRA007's Avatar
PRA007 PRA007 is offline How to do task based on paragraph numbering after find Windows 7 64bit How to do task based on paragraph numbering after find Office 2010 32bit
Competent Performer
How to do task based on paragraph numbering after find
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default How to do task based on paragraph numbering after find

I want to perform following task



1. find string "string"

2. for all find, on which paragraph number it was found and write some text file of the same if possible. Msgbox is also ok

3. delete 2 paragraph above and 2 paragraph below the found string
Reply With Quote
  #2  
Old 12-10-2015, 09:41 PM
PRA007's Avatar
PRA007 PRA007 is offline How to do task based on paragraph numbering after find Windows 7 64bit How to do task based on paragraph numbering after find Office 2010 32bit
Competent Performer
How to do task based on paragraph numbering after find
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

Update
3. delete 2 paragraph above and 2 paragraph below the found string and paragraph found
Reply With Quote
  #3  
Old 12-13-2015, 09:56 PM
PRA007's Avatar
PRA007 PRA007 is offline How to do task based on paragraph numbering after find Windows 7 64bit How to do task based on paragraph numbering after find Office 2010 32bit
Competent Performer
How to do task based on paragraph numbering after find
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

Is it not possible to find on which paragraph the found string are in word?
Reply With Quote
  #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,101
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 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
  #5  
Old 12-15-2015, 11:22 PM
PRA007's Avatar
PRA007 PRA007 is offline How to do task based on paragraph numbering after find Windows 7 64bit How to do task based on paragraph numbering after find Office 2010 32bit
Competent Performer
How to do task based on paragraph numbering after find
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 12-15-2015, 11:32 PM
PRA007's Avatar
PRA007 PRA007 is offline How to do task based on paragraph numbering after find Windows 7 64bit How to do task based on paragraph numbering after find Office 2010 32bit
Competent Performer
How to do task based on paragraph numbering after find
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

Works perfectly.
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.
Reply With Quote
Reply

Tags
word vba

Thread Tools
Display Modes


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 03:48 PM.


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