View Single Post
 
Old 07-21-2020, 04:14 AM
alex100 alex100 is offline Windows 7 64bit Office 2016
Advanced Beginner
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default

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
Alex
Reply With Quote