Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-23-2021, 02:46 PM
drrr drrr is offline a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection Windows 10 a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection Office 2019
Novice
a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection
 
Join Date: Jul 2021
Posts: 9
drrr is on a distinguished road
Default a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection

this should replace paragraph mark with a space on the selection only
but it applies to the selection and paragraph marks after the selection
it was created with record macro functionality

Code:
Sub clean()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Reply With Quote
  #2  
Old 08-23-2021, 04:06 PM
Guessed's Avatar
Guessed Guessed is offline a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection Windows 10 a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The issue is the wdFindAsk. Try .Wrap = wdFindStop instead.

And clean it up a little to bring it all inside the With...End With - I don't know why Microsoft records this abnormality
Code:
Sub clean()
    With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "^p"
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
    End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 08-24-2021, 03:05 AM
drrr drrr is offline a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection Windows 10 a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection Office 2019
Novice
a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection
 
Join Date: Jul 2021
Posts: 9
drrr is on a distinguished road
Default

thanks! it works
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection Skip double paragraph mark during find and replace in MS Word? Jakov93 Word VBA 2 07-13-2021 11:07 PM
Accepting track changes via macro skips last paragraph mark, but not when accepting via Review menu Peterson Word VBA 3 03-25-2020 10:03 PM
a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection Replace space with paragraph mark jeffreybrown Word VBA 8 08-22-2018 03:31 PM
a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection Paragraph marks appear suddently leonardevens Word 1 07-13-2015 12:14 PM
a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection Replace paragraph-marks (line-breaks) in tables with a character-string Aztec Word VBA 2 04-02-2013 10:52 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft