Forum Discussion
Comparing Documents with Hyperlinks
Doug_Robbins_Word_MVP Doug, really appreciate the reply. I did explore that option during my testing. The issue doing it that way will be that I may have 300-500 hyperlinks or possibly more in the future. If there is a 300-500 item code change I will now have to manually go through hundreds of items while trying to not delete out existing hyperlinks. That is why I was hoping to find a way to have the documents compared without the hyperlinks being included as changes.
FireProtection Running a macro containing the following code on the document created by the Compare function that I suggested, will result in the rejection of the deletion of any hyperlinks in that document with affecting any of the other revisions, which you could then accept to end up with a document free of revisions.
Dim arev As Revision
Dim i As Long
With ActiveDocument
For Each arev In .Revisions
If arev.Type = wdRevisionDelete Then
If arev.Range.Fields.Count > 0 Then
For i = arev.Range.Fields.Count To 1 Step -1
If arev.Range.Fields(i).Type = wdFieldHyperlink Then
arev.Reject
End If
Next i
End If
End If
Next arev
End With
- FireProtectionFeb 13, 2023Copper Contributor
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.
- Feb 13, 2023
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.