Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2021, 08:57 PM
Jakov93 Jakov93 is offline Skip double paragraph mark during find and replace in MS Word? Windows 10 Skip double paragraph mark during find and replace in MS Word? Office 2010
Advanced Beginner
Skip double paragraph mark during find and replace in MS Word?
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default Skip double paragraph mark during find and replace in MS Word?

Hi All

As this thread locked by the author:
Macro to delete new carriage returns / new paragraph marks - Microsoft Community

The author of this VBA code was Greg Maxey, and his code is awesome
My question, sometimes I add a double paragraph mark (Pressing enter twice) to separate between paragraphs, to distinguish each paragraph,


but when selecting the texts and applying the code, it will remove all paragraph marks and all the text merged in one paragraph, this makes trouble for me because it needs to reseparate each paragraph.

So, according to this VBA code, how to skip double paragraph marks during find and replace, to maintain each paragraph alone?

Thanks in advance
Reply With Quote
  #2  
Old 07-13-2021, 10:46 PM
gmayor's Avatar
gmayor gmayor is offline Skip double paragraph mark during find and replace in MS Word? Windows 10 Skip double paragraph mark during find and replace in MS Word? Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Greg is currently enjoying a much needed break so wouldn't be around to comment anyway. To retain the double paragraph breaks the following addition should work
Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
'Graham Mayor - https://www.gmayor.com - Last updated - 14 Jul 2021
Dim oRng As Word.Range
    Set oRng = Selection.Range
    If oRng.Characters.Last = Chr(13) Or oRng.Characters.Last = Chr(11) Then
        oRng.End = oRng.End - 1
    End If
    oRng.Text = Replace(oRng.Text, Chr(13) & Chr(13), "&%&%&%")
    oRng.Text = Replace(Replace(oRng.Text, Chr(11), " "), Chr(13), " ")
    oRng.Text = Replace(oRng.Text, "&%&%&%", Chr(13) & Chr(13))
lbl_Exit:
    Exit Sub
End Sub
though frankly for the future it would be better to use paragraph styles with added spacing to format the document to separate paragraphs than to use empty paragraphs. It makes the document much easier to edit.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 07-13-2021, 11:07 PM
Jakov93 Jakov93 is offline Skip double paragraph mark during find and replace in MS Word? Windows 10 Skip double paragraph mark during find and replace in MS Word? Office 2010
Advanced Beginner
Skip double paragraph mark during find and replace in MS Word?
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default

Thanks Sir gmayor
You are awesome too.

I agree with U that using styles is better, but the problem when copying different paragraph texts from pdf files, then applying Greg's code, all the paragraphs are merged into a single paragraph for entire document, and this annoying for me.

Again, thanks for your edition of the code
Best Regards
Reply With Quote
Reply

Tags
microsoft word 2016, vba word search, word 16



Similar Threads
Thread Thread Starter Forum Replies Last Post
Skip double paragraph mark during find and replace in MS Word? Word macro to insert text at the beginning of paragraph but skip tables ashalles135 Word VBA 5 09-26-2018 09:49 AM
Skip double paragraph mark during find and replace in MS Word? Replace space with paragraph mark jeffreybrown Word VBA 8 08-22-2018 03:31 PM
Skip double paragraph mark during find and replace in MS Word? Double click on a cell to add check mark? robbinskelly7 Excel 1 02-09-2015 07:05 PM
Find/Replace adds a style to what I'm searching for AND the following paragraph JFDI Word 2 03-27-2014 05:36 PM
Find bullets and replace with paragraph style? cdybdahl Word 1 12-02-2011 02:14 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:02 PM.


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