Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-27-2015, 10:50 PM
gmayor's Avatar
gmayor gmayor is offline Extracting lines containing specific word. Windows 7 64bit Extracting lines containing specific word. Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
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


It seems fairly straightforward. How about:

Code:
Sub ExtractText()
'Seb AllenThursday, 26 March 2015 at 16:13 UTC
Dim oSource As Document
Dim oTarget As Document
Dim oRng As Range
    Set oSource = ActiveDocument
    'Create a document to hold the extracts
    Set oTarget = Documents.Add
    'replace line breaks with paragraph breaks
    Set oRng = oSource.Range
    oRng.Text = Replace(oRng.Text, Chr(11), Chr(13))
    With oRng.Find
        'Find the times
        Do While .Execute(FindText:="at [0-9]{2}:[0-9]{2} UTC", _
                          MatchWildcards:=True)
            'Copy the paragraph containing the found time to the new document
            oTarget.Range.InsertAfter oRng.Paragraphs(1).Range.Text
            oRng.Collapse 0
            DoEvents
        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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting lines containing specific word. Extracting data from a cell with multiple lines of text MMT Excel 9 02-12-2015 09:18 PM
Extracting specific rows sbdk82 Excel 4 09-07-2014 10:24 PM
Formatting contents after Tab of continuous lines or formatting specific area of word pawii Word 1 05-12-2014 05:24 AM
Extracting lines containing specific word. Extracting information from Image in word Flambo Word 2 05-06-2012 10:43 PM
Extracting lines containing specific word. Need help extracting specific text from one doument to another with macro/VBA. zsmithku Word 1 04-15-2011 03:46 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:50 AM.


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