Consulting

Results 1 to 7 of 7

Thread: Find text and copy past that in another document

  1. #1

    Find text and copy past that in another document

    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

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    I would just copy the whole thing to a new document and then delete the lines you don't want, something like this:
    [VBA]
    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
    [/VBA]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3

    SOLVED

    Great Help. Thanks alot.

  4. #4
    Hi,

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

  5. #5
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Sheet? Do you want this in Excel?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  6. #6
    I am sorry for the confusion here. I need the result in new document.

  7. #7
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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 ...

    [VBA]
    For ...
    ....
    Next
    ActiveDocument.SaveAs FileName:=newpathandfilename
    [/VBA]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •