Consulting

Results 1 to 3 of 3

Thread: Macro to fix different error typos

  1. #1
    VBAX Regular
    Joined
    May 2018
    Posts
    6
    Location

    Macro to fix different error typos

    Hi there,


    I´m looking for a macro that makes the following fixes in a document:


    1. Any double dot at the end of a sentence should be replaced by a single dot.

    For example:

    Hello world.. >>> Hello world.

    2. Dot + space + dot at the end of a sentence should be replaced by a single dot.


    For example:

    Hello world. . >>> Hello world.

    3. word + double space + word should be replaced by replaced by a single space:


    For example:

    Hello world >>> Hello world

    Not sure if using wildcards will allow to do that in a single macro but will be very appreciated if so!

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    You don't need a macro, just a fewFind/Replace operations, where:
    Find = ..
    Replace = .
    Find = . .
    Replace = .
    Find = ^32^32
    Replace = ^32
    You could, of course, record these as a macro.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Quote Originally Posted by Fonsi View Post
    Hi there,

    1. Any double dot at the end of a sentence should be replaced by a single dot.

    2. Dot + space + dot at the end of a sentence should be replaced by a single dot.

    3. word + double space + word should be replaced by replaced by a single space:

    Single macro could do all that, but it's the 'end of a sentence' part that is a little tricky

    End of a paragraph part is easy, but it is possible to have a Dot+space+Dot somewhere NOT at the end of sentence (maybe unlikely, but possible)

    Maybe you could just assume a-z or 0-9 is the last character in the sentence


    Sub Macro1()
        With ActiveDocument.Content.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = "([a-z0-9]).{2,}"
            .Replacement.Text = "\1."
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        
            .Execute Replace:=wdReplaceAll
        
            .Text = "([a-z0-9]). {1,}."
            .Execute Replace:=wdReplaceAll
        
            .Text = " {2,}"
            .Replacement.Text = " "
            .Execute Replace:=wdReplaceAll
        End With
    End Sub
    Last edited by Paul_Hossler; 05-21-2018 at 09:18 AM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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