Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Jul 2015
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question MS Word Macro Help

    Greetings,

    I work with a lot of text embedded in tables. So to make my work more efficient I am in need of specific macro. I want that macro operates only within rows of selected column in such way so macro would change (dot+) or (dot+space+) to (dot+"shift enter") and in all other cases replace (Enter) with "space".

    Im not sure am I correct but my logic is that first swipe will change all specific to shiftenter so it will not collide with second swipe that will change to space.

    Thanks.

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Miodragz,

    Welcome to the Lounge as a New Poster!

    You can place this code in the This Document module of the document to be worked on or if you want it to operate on multiple documents you can Insert a Module in the Normal object and paste it there but don't forget to Save it (Ctrl+S) if you don't get prompted to save normal when you exit Word.
    Code:
    Option Explicit
    
    Sub FixParagraphsInSelection()
    
        With Selection.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = ".^p"
            .Replacement.Text = "#$%$#"
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .Execute Replace:=wdReplaceAll
        End With
        With Selection.Find
            .Text = ". ^p"
            .Replacement.Text = "#$%$#"
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .Execute Replace:=wdReplaceAll
        End With
        With Selection.Find
            .Text = "^p"
            .Replacement.Text = " "
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .Execute Replace:=wdReplaceAll
        End With
        With Selection.Find
            .Text = "#$%$#"
            .Replacement.Text = ".^l"
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .Execute Replace:=wdReplaceAll
        End With
        
    End Sub   'FixParagraphsInSelection
    Note: this macro will operated on the current selection what ever it is so don't forget to select the column in your table before running the macro.

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

Posting Permissions

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