Fixing external hyperlinks in Word documents


External hyperlinks generated with RPE 1.2.1 and newer do not work from Word (Ctrl+Click) as the address is prefixed with a “#”. This is a defect in RPE and and until the defet is fixed a solution is to use a post processing macro to identify and correct the hyperlinks.


Public Sub fixLinks()
   Dim lnk As Hyperlink

   ' RPE generated links are empty and the link is stored in the sub-address field
   For Each lnk In ActiveDocument.Hyperlinks
      If Len(lnk.address) = 0 And InStr(lnk.SubAddress, "http") = 1 Then
         lnk.address = lnk.SubAddress
      End If
   Next
End Sub

Advertisements

Author: Dragos Cojocari

Architect for Rational Publishing Engine

6 thoughts on “Fixing external hyperlinks in Word documents”

  1. (sorry, new to replying to your blog but following it since some time and maybe stupid question)
    How/where do you implement this post-processing code? Is it in the .dot file used for stylesheet or somewhere in RPE template?
    How do you secure automatic run of post-processing macro?

    Thx for all your excellent posts, I’ll reply on several on them gradually as I have feedback and questions (using RPE with Focal Point)

    1. Welcome to the ranks of commenters of this blog and thanks for your feedback and questions.

      On the macro topic:
      – the code goes indeed in the stylesheet used for the Word output and not in the template
      – to have the macro executed automatically at the end of the docgen you need to:
      a. specify the stylesheet for the Word output
      b. enter the name of the macro ( in this case fixLinks) in the “macro” property of the Word output

      See this for more details: http://www-01.ibm.com/support/docview.wss?uid=swg21395685

  2. This will really come in handy. We can also include “file” apart from “http”.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s