Thread: [Solved] Need Help with this Macro
View Single Post
 
Old 09-24-2018, 12:08 PM
Jefgorbach Jefgorbach is offline Windows 10 Office 2007
Novice
 
Join Date: Sep 2018
Posts: 2
Jefgorbach is on a distinguished road
Default

I think this accomplishes what you're trying to do.
I changed the Find-N-Replace code to a subroutine for easier reading and reuse.

Code:
Sub Macro6()
'Select your desired text to be changed then run the macro.
‘
Options.Pagination = False               'turn off background page counts for speed
Application.ScreenUpdating = False  'turn off screen changes for speed

With Selection
   .Font.Bold = wdToggle     'toggle selection's Bold state
   Call Swap(“^p^p”,”<P>”) ‘placeholder between paragraphs
   Call Swap(“^p”,” “)          ‘condense sentences
   Call swap(“<P>”,”^p^p”) ‘separate paragraphs again
End with
Selection.WholeStory.Font.Bold = wdToggle  'toggle entire document Bold state; why?
Selection.EscapeKey                                   ‘unsure if you need to exit selection?
Application.ScreenUpdating = True  'turn screen changes back on
Options.Pagination = True               'turn background page counts back on
End Sub


Sub Swap(First, Second)
With Selection
    .Find.ClearFormatting
    .Find.Replacement.ClearFormatting
    With Selection.Find
           .Text = First
           .Replacement.Text = Second
           .Forward = True
           .Wrap = False
           .Format = False
           .MatchCase = False
           .MatchWholeWord = False
           .MatchWildcards = False
           .MatchSoundsLike = False
           .MatchAllWordForms = False
       End With
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Last edited by macropod; 09-24-2018 at 05:30 PM. Reason: Added code tags & formatting
Reply With Quote