#1
|
|||
|
|||
Replace double-paragraphs
I have been using the script below to find and replace double-paragraph signs. It works ok, with an exception.
For some reason, it won't work with Quora.com pages. For example, please go to the address below and select & copy all the "Related Questions" text at the bottom of the page... What makes you buy an Apple product? - Quora Then paste this content to a Word document, and finally run this script... Code:
With ActiveDocument.Content.Find .Execute FindText:="^p^p", ReplaceWith:="^p", Wrap:=wdFindStop, Replace:=wdReplaceAll End With Any idea how I could make it work, please? Thank you! Alex |
#2
|
|||
|
|||
If you change FindStop to FindContinue ?
__________________
Backup your original file before doing any modification. |
#3
|
|||
|
|||
Quote:
Those 'related questions' at the bottom of the page are all links, and I believe this is the main reason for the script not working. As soon as I remove the links using the 'Remove Hyperlink' Word function, the script does start to work properly and replace the double paragraphs. It's probably about the paragraphs that take the same property as the links next to them, and this will prevent the script to find them. It must be something like this, not sure exactly... Any help would be appreciated. Alex Last edited by alex100; 07-19-2020 at 11:10 AM. |
#4
|
||||
|
||||
That content is showing paragraph marks either end of a hyperlink. This means that there is 'something' in between the consecutive paragraph marks (ie a start or end hyperlink code).
If you replace all single paragraph marks with zz you see it hits them all. If you remove the hyperlinks you also see your original macro works as expected. I suggest you rework your macro to remove paragraph marks from inside the Hyperlink ranges.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Quote:
Quote:
Anyhow, if any of you already use a routine that is able to replace all double paragraph marks & carriage returns (including those inside hyperlink ranges, as explained above), it would be great if you could please share it here. Thank you! Alex |
#6
|
||||
|
||||
Try this
Code:
Dim aHL As Hyperlink, sText As String For Each aHL In ActiveDocument.Hyperlinks sText = aHL.Range.Text sText = Replace(sText, Chr(13), "") aHL.TextToDisplay = sText Next aHL With ActiveDocument.Content.Find .Execute FindText:="^p^p", ReplaceWith:="^p", Wrap:=wdFindStop, Replace:=wdReplaceAll End With
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
|||
|
|||
Wonderful, thank you very much! It works great!
I made a few changes. These are mostly personal preferences, but I'm pasting them here in case someone else might be interested in applying them. Otherwise, they can easily be removed. Here they are, together with the code: 1) i need double-paragraphs to be replaced by a single paragraph, not entirely removed; 2) links are now blue and underlined; 3) during testing with various other content, I found some links that still had some large vertical space in between them, but that was only because of the 'ParagraphFormat.SpaceAfter' property, which is now set to 0; 4) I also found some links that had no anchor text at all - these will get deleted. Code:
Dim aHL As Hyperlink, sText As String For Each aHL In ActiveDocument.Hyperlinks sText = aHL.Range.Text sText = Replace(sText, Chr(13), "") aHL.TextToDisplay = sText + Chr(13) aHL.Range.Font.Color = vbBlue aHL.Range.Font.Underline = wdUnderlineSingle aHL.Range.ParagraphFormat.SpaceAfterAuto = False aHL.Range.ParagraphFormat.SpaceAfter = 0 If sText = "" Then aHL.Delete End If Next aHL With ActiveDocument.Content.Find .Execute FindText:="^p^p", ReplaceWith:="^p", Wrap:=wdFindStop, Replace:=wdReplaceAll End With |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Search and replace, with paragraphs and wildcards | alex100 | Word VBA | 3 | 05-16-2020 08:43 AM |
double spaced within paragraph 2 blank lines between paragraphs | BigOldArt | Word | 1 | 08-24-2017 09:08 AM |
Replacing till there's no more double paragraphs in the text | eduzs | Word VBA | 25 | 07-01-2017 04:04 PM |
Find and Replace multiple lines/paragraphs | jcw | Word | 1 | 11-18-2011 11:47 AM |
outlook double spacing paragraphs | GWBDIRECT | Outlook | 3 | 04-06-2011 11:29 AM |