#1
|
|||
|
|||
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. |
#2
|
||||
|
||||
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 |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 information from Image in word | Flambo | Word | 2 | 05-06-2012 10:43 PM |
Need help extracting specific text from one doument to another with macro/VBA. | zsmithku | Word | 1 | 04-15-2011 03:46 PM |