PDA

View Full Version : Find text and copy past that in another document



ap_naveen
12-06-2007, 05:07 AM
I had word file which consists of some records with some information as shown in bleow
.

RECORD ID: 02816914 PROBLEM DESCRIPTION:
PROBLEM REPORTER DATA PROBLEM ASSIGNMENT DATA
REPORTER NAME ------ AF/OPER INITIAL ASSIGNMENT
DATE OCCURRED ------ 12/04/07
TIME OCCURRED ------ 00:39
DATE ENTERED ------- 12/04/07 DATE RECOVERED ------ 12/04/07
TIME ENTERED ------- 00:39 TIME RECOVERED ------
PROBLEM INFORMATION RESOLVER INFORMATION
JOB NAME -----------AB1234 RESOLVER CLASS ------ 77777
PROGRAM NAME ------- N/A DATE CLOSED --------- 12/04/07
SYSTEM ID ---------- L123 TIME CLOSED --------- 04:09
ABEND CODE --------- FI1213
SEVERITY CODE ------ 04 PROBLEM STATUS ------ CLOSED
FREEFORM TEXT:
12/04/07 04:05 TBNAVAM PRODUCT: BAJAJ

RECORD ID: 02816915 PROBLEM DESCRIPTION:
PROBLEM REPORTER DATA PROBLEM ASSIGNMENT DATA
REPORTER NAME ------ AF/OPER INITIAL ASSIGNMENT
DATE OCCURRED ------ 12/04/07
TIME OCCURRED ------ 00:39
DATE ENTERED ------- 12/04/07 DATE RECOVERED ------ 12/04/07
TIME ENTERED ------- 00:39 TIME RECOVERED ------
PROBLEM INFORMATION RESOLVER INFORMATION
JOB NAME -----------AB1234 RESOLVER CLASS ------ 77777
PROGRAM NAME ------- N/A DATE CLOSED --------- 12/04/07
SYSTEM ID ---------- L123 TIME CLOSED --------- 04:09
ABEND CODE --------- FI1134
SEVERITY CODE ------ 04 PROBLEM STATUS ------ CLOSED
FREEFORM TEXT:
12/04/07 04:05 TBNAVAM PRODUCT: MARUTI

Now I am looking for a macro which reads the each line from starting to till the end of the document.
It should search for RECORD ID, ABEND CODE AND PRODUCT.
And if any word found the macro should copy paste the total line of that another new document.
Like below result in another document
RECORD ID: 02816914 PROBLEM DESCRIPTION:
ABEND CODE --------- FI1213
PRODUCT: BAJAJ

RECORD ID: 02816915 PROBLEM DESCRIPTION:
ABEND CODE --------- FI1134
PRODUCT: MARUTI
Could anyone please help with me the macro. Your help much appreciated

TonyJollans
12-07-2007, 12:17 AM
I would just copy the whole thing to a new document and then delete the lines you don't want, something like this:

For Each P In ActiveDocument.Paragraphs
Select Case True
Case InStr(P.Range.Text, "RECORD ID:")
Case InStr(P.Range.Text, "ABEND CODE")
Case InStr(P.Range.Text, "PRODUCT:")
Case Else: P.Range.Delete
End Select
Next

ap_naveen
12-07-2007, 01:34 AM
Great Help. Thanks alot.

ap_naveen
12-10-2007, 03:46 AM
Hi,

I would like to see the result in new sheet. Please advise and Thanks in advance for your help

TonyJollans
12-10-2007, 05:06 AM
Sheet? Do you want this in Excel?

ap_naveen
12-10-2007, 05:09 AM
I am sorry for the confusion here. I need the result in new document.

TonyJollans
12-10-2007, 05:43 AM
I did say to begin with to copy to a new document but if you simply do a SaveAs after the code you will get a new document ...


For ...
....
Next
ActiveDocument.SaveAs FileName:=newpathandfilename