Consulting

Results 1 to 10 of 10

Thread: Solved: Find all ' in all word inserted in curly bracket

  1. #1

    Solved: Find all ' in all word inserted in curly bracket

    Hallo I need yet help.
    I have a long doc with words at the begin of phrase and others inserted in curly bracket.
    I must repalce all ' (apostrophes) of the words inserted in curly Bracket when it is follow by a space with ' (apostrophes) without space.
    Sample:
    Gen 1:9 Dio disse: Siano raccolte in un sol luogo le acque che sono sotto il cielo e appaia l' asciutto. E cos? avvenne.{1,9 ieri sera l' origine della storia l' oriente other word d' ordine, c' era ecc.}.

    replace with:
    Gen 1:9 Dio disse: Siano raccolte in un sol luogo le acque che sono sotto il cielo e appaia l' asciutto. E cos? avvenne.{1,9 ieri sera l'origine della storia l'oriente other word d'ordine, c'era, ecc.}.


    (Hi Tony - I have effort to solve it by is very difficult for me.

    Pasquale

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Pasquale,

    I don't think this one can be done with a single Find and Replace

    But this:

    Find what: \{(*)' (*)\}
    Replace with: {\1'\2}
    Use wildcards: checked

    Will replace a single occurrence of (apostrophe space) with (apostrophe).

    You could manually do Replace All until you get a message telling you that zero replacements were made - or you could record doing it once and make a loop by changing the Execute to something like:

    [VBA]While Selection.Find.Execute(Replace:=wdReplaceAll):Wend[/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
    Hi Tony,
    The find and replace, select also the text not inserted in curly bracket. It select large parts of text inserted and not inserted in curly bracket. The doc is very long and alternate parts inserted in curly bracket and not inserted in curly bracket.
    Thanks pasquale

  4. #4
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Sorry, Pasquale.

    I just did a quick test on your posted sample and, of course, it worked but I didn't think about what would happen when you had lots of the stuff in a single document.

    I'm away for the rest of the day - I'll think about how best to do it and come back tomorrow. The two-character combination is a bit of a problem.

    One way, perhaps, would be to change ALL (apost space) to some otherwise unused character, say ? for this example, - then search for (\{[!\}?]{1,})?([!\{\}]{1,}\}) and replace all with \1'\2 till there are no more (with the loop) - then replace all ? with (apost space) again - to set back the ones outside braces.
    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

  5. #5
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Pasquale,

    I think the way I outlined is as good as any - here's some code which should do it:
    [VBA]
    Selection.HomeKey wdStory

    With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True

    .Text = "' "
    .Replacement.Text = "?"
    .Execute Replace:=wdReplaceAll

    .Text = "(\{[!\}?]{1,})?([!\{\}]{1,}\})"
    .Replacement.Text = "\1'\2"
    While .Execute(Replace:=wdReplaceAll): Wend

    .Text = "?"
    .Replacement.Text = "' "
    .Execute Replace:=wdReplaceAll
    End With
    [/VBA]

    In the unlikely event of you having any ? characters in your document already, then replace it with some other character (which isn't in your document) everywhere it's used (three places).
    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
    Hi tony,
    it doesn't works in all words inserted in curly bracket, but only in a few pieces of text inserted in curly bracket, i post a file.
    Thanks
    pasquale

  7. #7
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Pasquale,

    Well, there's something I've learnt today - and before breakfast.

    This looks like it is going to require more complex code than it really should. I will post back later.
    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

  8. #8
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Pasquale,

    Want to try this one?
    [VBA]
    Selection.HomeKey wdStory

    With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    End With

    Do
    Selection.Collapse wdCollapseEnd

    With Selection.Find
    .Text = "\{*\}"
    .Replacement.Text = ""
    .MatchWildcards = True
    If Not .Execute Then Exit Do

    .Text = "' "
    .Replacement.Text = "'"
    .MatchWildcards = False
    .Execute Replace:=wdReplaceAll
    End With

    Loop[/VBA]

    What did I learn? That the construct {1,} which means "one or more occurrences of the preceding element" actually means from 1 to 255 occurrences. The joys of Word!
    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

  9. #9
    Hi tony, it works very very well. I test yet.

    pasquale

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