Programatically add section of records in a text file

Posted on 2012-09-04
Last Modified: 2012-09-05
I have a text file that contains thousands of record sets.  For each of these record sets, the last record starts with SE*.

I want to programatically add several records directly before this record in each record set.  

Example: Here is an example of the the record set.  For record set A and B they both end with SE* Record.  I basically need to be able to add 4 additional records before each of the SE* Records.  The records to add are all the same.  So say in my VB macro I run in Word will need to find the first SE* Record, and add the 4 records above it (just call these New record 1, New Record 2, New Record 3....  Then loop through the rest of the file finding each of the remaining SE* Records and add the same 4 records as mentioned previosly.

Record 1a
Record 1b
Record 1c
Record 1d
New Record 1
New Record 2
New Record 3
New Record 4
SE* record
Record 2a
Record 2b
Record 2c
New Record 1
New Record 2
New Record 3
New Record 4
SE* record
Question by:66chawger
    LVL 92

    Accepted Solution

    You can do this without code.  Just open the file in Word, and use Find/Replace with this as the Find string:

    SE* Record

    and this as the Replace string:

    New Record 1^pNew Record 2^pNew Record 3^pNew Record 4^pSE* Record

    Author Comment

    So simple... forget sometimes how much you can do with find and replace.

    Author Closing Comment

    Simple solution.  Worked great!

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
    My experience with Windows 10 over a one year period and suggestions for smooth operation
    The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
    The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now