Consulting

Results 1 to 8 of 8

Thread: Wordlists Find/Replace Within Each Paragraph Separately

  1. #1

    Wordlists Find/Replace Within Each Paragraph Separately

    I use find/replace a lot with wordlists. The wordlists generally contain one word/phrase within each paragraph. I'm trying to create a macro that will:


    • Find/replace text within each paragraph separately.
    • If it finds "}" (for example) within a paragraph, it'll replace with a tab, then move to the next paragraph.
    • If "}" is not found within a paragraph, it'll move to the next paragraph and find again.


    Relatedly, I would potentially try to find/replace from the start of a paragraph up to the "}" character, but not beyond that character within each paragraph. Is there a simple way to do that?


    Appreciate any help!

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,648
    Location
    Except for the mention of wordlists, there is nothing about what you've described to suggest either that a macro is required or that paragraphs, as such, are a relevant consideration. For what you've described, a simple Find/Replace with:
    Find = }
    Replace = ^t
    would do.

    As for word list processing, I've previously provided you with code to do just that. This kind of thing has already been discussed and resolved in many other threads, too. Instead of expecting to be spoon-fed solutions for each new problem, you should make some effort to learn from what you've already been provided and from the other resources available from this forum. Do that and, if you get stuck, post back with the relevant code and we'll happily provide more guidance.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  3. #3
    Apologies for providing a meaningless example. The purpose I'm thinking of currently is to move to the next paragraph after the first successful find/replace within each paragraph. So, based on my original example, assume there are multiple } characters within several of the paragraphs, and that I only want to find/replace the first one in each paragraph.

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,648
    Location
    Even that only requires a fairly straightforward wildcard Find/Replace, where:
    Find = \}(*^13)
    Replace = ^t\1
    Cheers
    Paul Edstein
    [MS MVP - Word]

  5. #5
    Say I want to replace all the "A" characters before, but not after, the "}" character within each paragraph. If there's no "A" before the "}" character in a paragraph, but there is one after the "}" character, finding/replacing "\}(*^13)" will modify the text after the "}" character on one paragraph until the end of the following paragraph.

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,648
    Location
    You really should spend a bit of time learning the wildcard syntax. As it is, it's not apparent to me whether you want to process all A} sets (in which case you might use Find = A\}) or just the first one (in which case you might use Find = A\}(*^13)); neither is it apparent what you want to do with those A characters.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  7. #7
    I'm familiar with the wildcard syntax. All the examples you've provided effectively do the same thing – if it finds an "A" after the "}" character but not before it, it'll find text out of sequence from that point in the document.

    I want to find/replace the "A" characters before the "}" character within each paragraph; if there isn't an "A" character before the "}" character in each paragraph, I want to stop the find process at the "}" character and restart it from the start of the next paragraph. So, searching only between the start of a paragraph and the "}" character.

  8. #8
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,648
    Location
    Quote Originally Posted by VB-AN-IZ View Post
    All the examples you've provided effectively do the same thing – if it finds an "A" after the "}" character but not before it, it'll find text out of sequence from that point in the document.
    Unless you're starting the Find with the insertion point after the first A} sequence in a paragraph, that simply isn't so. You could confirm that by doing a wildcard Find/Replace where:
    Find = A\}(*^13)
    Replace = X\1
    Quote Originally Posted by VB-AN-IZ View Post
    I want to find/replace the "A" characters before the "}" character within each paragraph; if there isn't an "A" character before the "}" character in each paragraph, I want to stop the find process at the "}" character and restart it from the start of the next paragraph. So, searching only between the start of a paragraph and the "}" character.
    Unless you're now saying that if there's a } before the first A} you want to skip the entire paragraph - which is a completely different proposition from what you previously said - the expression I gave you already does that if you don't
    start the Find with the insertion point after the first A} sequence in a paragraph.
    Cheers
    Paul Edstein
    [MS MVP - Word]

Tags for this Thread

Posting Permissions

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