|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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] |
#3
|
|||
|
|||
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! |
#4
|
||||
|
||||
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] |
#5
|
|||
|
|||
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 |
#6
|
||||
|
||||
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] |
Tags |
field, hyperlink, vba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Why are style updates in VBA not reflected in the document? | FlyingBlind | Word VBA | 5 | 02-16-2019 01:57 PM |
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 |
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 |