Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Jul 2005
    Location
    Bahrain
    Posts
    373
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Extracting paragraphs

    Greetings,
    I have a 100 page document. The paragraphs in the document ends with codes like “SAM”, “GAMD”, ”BD&WT” in brackets “()”. What I need is a code that enables me to do extract based on multiple codes with inclusion of the paragraph heading.
    TIA
    dubdub

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    This sounds suspiciously like you are trying to create a compliance table from the document. You can do this processing by vba code but since we have very little information to go on I am not going to attempt the coding.

    Instead, try to work out how you might do this with a series of search and replaces. If you can inject a tab in front of the code then you could either convert to table or copy into Excel and then add a unique id (incrementing number) before sorting on the code column. The unique id will let you rearrange the document contents if required.

    If you need a code solution, you need to provide more details on what exactly you need and also provide a sample document so we can code to that.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    2 Star Lounger
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    122
    Thanks
    3
    Thanked 20 Times in 18 Posts
    If you use Find and Replace to tag any paragraphs containing your codes with a unique style, you could then use Find to extract all instances of the tagged paragraph. For example:

    1. Using the Find and Replace dialog...
    Find what box: (GAMD)
    Replace with box: ^& and use Format to set Style: Quote
    Replace All

    2. Use the Find dialog (not the Find pane) with nothing in the Find what box, but set Format to choose the Quote style. When you click the Find In button, it will highlight (select) all paragraphs set with the Quote style. Drop out of the dialog and use Ctrl-C to copy the selection.

    3. Move your focus to where you want the extracted ¶s and use Ctrl-V to paste them.

    Repeat step #1 for the other codes to be able to pull them all at once in #2 & 3.

    Any paragraph style will work; I've just used Quote here as an example. The ^& token in #1 replaces the found code with itself, so it just acts as a holder to set the style for paragraphs containing it.

  4. #4
    3 Star Lounger
    Join Date
    Jul 2005
    Location
    Bahrain
    Posts
    373
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Many Thanks Eric,
    wonderful, is there a way to include the headings under which the highlighted code exist, also is there a way to include multiple codes using this procedure.
    Last edited by dubdub; 2014-11-30 at 05:29.
    TIA
    dubdub

  5. #5
    5 Star Lounger Lugh's Avatar
    Join Date
    Jun 2010
    Location
    Indy
    Posts
    619
    Thanks
    166
    Thanked 75 Times in 66 Posts
    Quote Originally Posted by dubdub View Post
    is there a way to include multiple codes using this procedure.
    Record a macro of the steps for one code, eg the (GAMD) one. Save it, and test to make sure it works as you expect. Once happy, copy the macro and replace (GAMD) with another of the codes. Repeat for each code.

    You now have a bunch of macros you can run in sequence one at a time, or you can copy them into one long macro which will auto run the job for all codes--in such cases, I prefer to write a higher-level macro which will "CALL" each of the single ones.

    Quote Originally Posted by dubdub View Post
    is there a way to include the headings under which the highlighted code exist.
    I'm not clear what you're asking. Guess: The paragraph heading is a separate paragraph immediately above the body text paragraph with the code. Is that it?

    If yes, I can't think of a way to do it offhand. Hopefully someone else can help.

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    If the headings use a Heading Style, or at least a consistent Style that isn't used elsewhere, it's not that hard with VBA, but you'd need to provide the details.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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