Consulting

Results 1 to 3 of 3

Thread: Word macro to rearrange paragraphs

  1. #1

    Word macro to rearrange paragraphs

    Hello!

    I am having trouble finding the right VBA code for the following:

    I work with draft documents on Word that have several consecutive paragraphs. At the end of the document, there are several more individual lines with time stamps.

    The lines with the time stamps can look like this:
    - There is a time stamp followed by some italic text. This line forms a section.
    - There is a time stamp followed by some text in bold. After the bold text, there is a line of italic text. These two lines form a section that is independent of the other section.

    So each time stamp initiates its own time stamp section. The next time stamp section starts with the next time stamp.

    You can see an example of how this document can look like in the Word doc attached ('Example text_rough'). The words 'Text' are meant as a placeholder for actual sentences. The 'XX:XX' are the time stamps. I highlighted the lines with the time stamps in yellow so you can distinguish. The actual documents I work with don't have yellow highlights.

    I then rearrange the paragraphs so that each time stamp section introduces two paragraphs. So first you have time stamp section 1 and then paragraphs 1 and 2 below. Then you have time stamp section 2 and then paragraphs 3 and 4 below. This continues until the last time stamp is at the end. You can see the new arrangement in the attached Word doc called 'Example text_arranged'.

    What I want is to have a macro that automates these steps, rearranging the time stamp sections and the paragraph sections. The documents I work with can have different lengths of paragraphs and the time stamp sections can also look different than in the docs attached. Sometimes there are several consecutive time stamp sections that have only one line, sometimes there are also several consecutive time stamp sections that have more than one line. But what always stays the same is that one time stamp section ends when the next time stamp shows up, as this next time stamp initiates the next time stamp section.

    Thank you for helping me out on this. I think it is a very specific issue but I can imagine that there is a way to automate this process. I tried to find a way using ChatGPT but the solutions it offered weren't working as I often got error messages.

    Thanks!
    Attached Files Attached Files

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,236
    Location
    Welcome to VBAX Santiago H. I. notice you have cross posted this issue at the msoffice forums as well.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Hello Aussiebear!
    I see now that it's better to cross-reference the threads so that users already know that my issue has been solved if this is the case. A little beginner's mistake on my part.
    I now added the link to this thread on the other forum, but wasn't able to see how to edit this one. I prefer to add the link on the very top so that other users know.
    But in any case, here is the link to the other thread: Help needed: Word macro to rearrange paragraphs (msofficeforums.com)
    Thank you for having flagged!
    Last edited by Santiago H.; 07-24-2024 at 02:52 AM.

Posting Permissions

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