View Single Post
 
Old 03-13-2020, 03:33 AM
JellehFishh JellehFishh is offline Windows 7 64bit Office 2010
Novice
 
Join Date: Jun 2019
Posts: 5
JellehFishh is on a distinguished road
Default Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document

Hi all,

I have been using the following macro for a long time and it works great, one significant improvement is if I can get it to also change PreserveFormatOnUpdate = True, but I can't figure it out!

Any help would be greatly appreciated!!


Code:
Sub HyperlinkFormatting()
    Dim fld As Field
    Dim Resp

    ' If no documents are open then exit
    If Documents.Count = 0 Then
        Exit Sub
    End If
    
    ' Confirm the action to format all the hyperlinks in the document
    Resp = MsgBox("Are you sure you want to format all the hyperlinks in this document?", _
        vbYesNo + vbQuestion + vbDefaultButton2, "Format Hyperlinks - Confirm?")
        
    If Resp = vbNo Then
        Exit Sub
    End If
    
    ' Loop through all fields in the active document
    For Each fld In ActiveDocument.Fields
        If fld.Type = wdFieldPageRef Or _
            fld.Type = wdFieldRef And InStr(1, fld.Code, "\h", 1) <> 0 Or _
            fld.Type = wdFieldHyperlink Then
            
                fld.Locked = False
                fld.Result.Font.ColorIndex = wdBlue
                
        End If
    Next fld
End Sub
Reply With Quote