Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-27-2015, 09:21 AM
S.Allen S.Allen is offline Extracting lines containing specific word. Windows 7 64bit Extracting lines containing specific word. Office 2007
Novice
Extracting lines containing specific word.
 
Join Date: Mar 2015
Posts: 1
S.Allen is on a distinguished road
Default Extracting lines containing specific word.

Hello.



I quite desperately need some assisstance. I am trying to collate information together to be used as supporting evidence for a visa application.

The evidence is essentially just copied and pasted to word facebook messages (need to establish a relationship has existed). There are 2.5 thousand pages of messages.

What I want to do is get rid of the message part, and just extract the line which contains the sender and time/date info. For example, a message appears like this:

Seb AllenThursday, 26 March 2015 at 16:13 UTC

Gracias!!


Sender, time and date info on one line, followed by the message. My thoughts are that it is possible to use the UTC to extract the line. So any line containing the phrase 'UTC' could be extracted? I have basic VBA knowledge, but I'm super rusty.

Any help is greatly appreciated.
Reply With Quote
  #2  
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,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

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

Thread Tools
Display Modes


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 01:57 AM.


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