Feb 11 2023 11:43 AM
Feb 11 2023 11:43 AM
I work in a Code Enforcement role and would like to make an interactive version of the Ontario Fire Code (https://www.ontario.ca/laws/regulation/070213). I would like to include multiple hyperlinks within the document so that if the code says 'go to this standard' or if we have internal documents speaking to a specific code reference our staff can simply click on the hyperlink and a document or folder will open.
The government regularly updates the code and I don't want to have to re-do this each time there is a code update. I would also like to try and avoid having to manually cut and paste all of the revisions into the word document.
In the test runs I have done the compare document seems to flag my hyperlinks and then remove the links. Is there a way to use the 'compare document' function to create an updated document without losing all of the hyperlinks?
Feb 11 2023 11:51 PM
@FireProtection If you use the Compare facility to compare your document with the Hyperlinks with the revised document selecting for the changes to be shown in the revised document, your Hyperlinks will be marked as deleted text and you can right click on each one and then reject the deletion which will reinstate the Hyperlink in the copy of the revised document created by the Compare facility.
Feb 12 2023 03:36 AM
@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.
Feb 12 2023 02:03 PM - edited Feb 12 2023 02:06 PM
@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
Feb 12 2023 06:14 PM
@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 06:25 AM
@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 03:22 PM
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
Feb 16 2023 05:26 PM