Forum Discussion
Comparing Documents with Hyperlinks
Doug_Robbins_Word_MVP This Macro almost does exactly what I was trying to accomplish. It does create one small issue. It double's up the text. I had made the entire standard name the hyperlinked text. The below snip is from the compared document, you can see it doubled up the text. The first version still has the hyperlink, the second does not and is redundant.
FireProtection Can you upload a copy of the document as it was before running the macro (You should be able to produce such a document by running the Compare process again) so that I can see what is that and perhaps fine tune the macro.
- FireProtectionFeb 13, 2023Copper Contributor
Doug_Robbins_Word_MVP I tried to upload the .docx file, however, it says the file is not supported. As a result, here is the process I took;
Initial Document - https://www.ontario.ca/laws/regulation/070213/v13 - I copy and pasted all text from 'Fire Protection and Prevention Act, 1997' in Bold down to 'O. Reg. 213/07, Division C; O. Reg. 150/13, s. 22; O. Reg. 194/14, s. 11; O. Reg. 256/14, ss. 432-439' at the bottom.
As this is the initial document it represents the 'older' version of the code.
Updated Version - https://www.ontario.ca/laws/regulation/070213 - I copy and pasted from the same two spots. This represents the updated code.
The only formatting I did to both documents was making it Landscape and setting the margins to narrow.
Your macro was copy and pasted into the macro section and simply named 'hyperlink'.
I compared both documents. No changes were made to the default settings. Once the compared document was displayed on the screen I scrolled down and noted that the Hyperlink was removed. I ran your Macro and noted that the hyperlink was restored.
Once I accepted all of the changes (I accepted them all blindly without reviewing as this is a test) I noticed that the text was doubled. The first portion contained the hyperlink the second did not.
- Feb 13, 2023
Hi David,
If you run a macro containing the following code on the compared document, it will stop with the selection immediately after a Hyperlink
so that you can determine what action to take. After taking that action, move the selection down one line and then run the macro again to move to the next hyperlink. If no action is required, just run the macro again and it will move to the next hyperlink.
Dim afield As Field Dim rng As Range With ActiveDocument Set rng = .Range rng.Start = Selection.Range.Start For Each afield In rng.Fields If afield.Type = wdFieldHyperlink Then afield.Select Selection.Collapse wdCollapseEnd Exit Sub End If Next afield End With- FireProtectionFeb 16, 2023Copper ContributorDoug, I still have some playing around to do with this Macro, however, I do believe this is going to work. It is going to allow for an appropriate amount of human intervention to ensure that mistakes are not being made while not involving too much intervention making it an onerous task.
I really appreciate your help and support on this item.