Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-13-2020, 03:33 AM
JellehFishh JellehFishh is offline Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Windows 7 64bit Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Office 2010
Novice
Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document
 
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
  #2  
Old 03-14-2020, 04:25 AM
macropod's Avatar
macropod macropod is offline Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Windows 7 64bit Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You're presumably wanting to add the \* MERGEFORMAT switch to the fields, though I can't imagine why you'd want to do that. It generally adds little of use and, with cross-references especially, that cause them to misbehave when you add content to the bookmarked range they reference. Obviously, though, if the field already has a \* MERGEFORMAT switch, you wouldn't want to add a second one.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-16-2020, 05:50 AM
JellehFishh JellehFishh is offline Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Windows 7 64bit Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Office 2010
Novice
Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document
 
Join Date: Jun 2019
Posts: 5
JellehFishh is on a distinguished road
Default

I had considered that might be the case, but I'm very much a novice with VBA.

The problem I have is that the macro turns hyperlinks blue, but they revert to black whenever they are updated (unless preserve formatting during update is enabled). I often find myself having to manually change this setting on every cross-reference within a document which is a chore, so I'm looking at macros. Ideally this could have just been chucked into the existing macro seeing as they would generally always both be run together, but maybe I'm just making more work for myself.

Any suggestions will be graciously received!
Reply With Quote
  #4  
Old 03-16-2020, 03:35 PM
macropod's Avatar
macropod macropod is offline Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Windows 7 64bit Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Why are you modifying the hyperlinks in code? They're blue by default, turning purple when followed. And, if you want cross-references to appear & act as hyperlinks, maybe you should be using hyperlinks for those, too.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-17-2020, 06:16 AM
JellehFishh JellehFishh is offline Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Windows 7 64bit Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Office 2010
Novice
Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document
 
Join Date: Jun 2019
Posts: 5
JellehFishh is on a distinguished road
Default

Only where the "Hyperlink" and "FollowedHyperlink" character styles are used, which they are not for cross-references.
Cross-references must be used as the text making up the hyperlink (typically a section heading or caption number) is liable to change.

Thanks
Reply With Quote
  #6  
Old 03-17-2020, 02:47 PM
macropod's Avatar
macropod macropod is offline Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Windows 7 64bit Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your cross-reference modifications won't work because you're not applying a \*Charformat switch to them or, alternatively, applying a suitable Style (e.g. the Hyperlink Style) to their range. And, whatever you do, you won't be able to have cross-references change colour the way followed hyperlinks do.

Finally, none of this explains why you're messing with the hyperlinks.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
field, hyperlink, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Why are style updates in VBA not reflected in the document? FlyingBlind Word VBA 5 02-16-2019 01:57 PM
Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document A mystery: how to hop about in a document, inserting updates in a single, new font? markh10178 Word 3 11-26-2015 04:07 PM
Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document Updates tries to install Office 2010 updates which I don't use jlumbtx Office 1 03-13-2015 04:50 PM
Automating document updates with new text wordfoolish2 Word 0 01-04-2011 01:01 PM
Hyperlinks get messed when adding or deleting some slides? Learner7 PowerPoint 0 05-17-2010 04:39 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:33 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