Results 1 to 4 of 4
  • Thread Tools
  1. New Lounger
    Join Date
    Apr 2012
    Location
    Massachusetts, USA
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Convert hyperlink to page-number references redux

    I'm a technical writer who needs to add the page number after a hyperlink. Another help author had posted this question back in 2008 and ended up with a working macro. I used his macro and although it works (I get the correct page number), the formatting is off. I don't know if it's because I'm using later versions of the software or if something else is off. (I'm using RoboHelp HTML v9 and Word 2010).

    Here's the link to his original post (now closed):
    http://windowssecrets.com/forums/sho...PageRefs%28%29

    To summarize, we're both using a help authoring tool called RoboHelp. RoboHelp allows you to basically Save As Word, which gives you a nice document to print. However, a clickable hyperlink is useless in a printed document. In a printed document, you want the hyperlink to be presented with a page number.

    Here's the link to the macro he ended up with and which I'm trying to use. (See Add Page Numbers after hyperlinks in RoboHelp Printed Documentation.)
    http://www.grainge.org/pages/authori...ord_macros.htm

    The macro works, but the formatting is wrong.

    My original text
    Click the Attachment button.

    After I run the macro
    Click the Attachment button (page 16).

    What can I do to get the result to have the underline in the right place? Either of these formats would do. I would consider getting rid of the link altogether, but I know that some user will open up a version of the Word file and want to be able to use real hyperlinks there.

    Click the Attachment button (page 16).
    Click the Attachment button (page 16).

  2. Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,349
    Thanks
    0
    Thanked 95 Times in 93 Posts
    Try the following revised version of the code:
    Code:
    Sub InsertPageRefs()
    Application.ScreenUpdating = False
    Dim hLnk As Hyperlink, Rng As Range
    For Each hLnk In ActiveDocument.Hyperlinks
      With hLnk
        If InStr(.SubAddress, "_Toc") = 0 And .Address = "" Then
          Set Rng = .Range
          With Rng
            .Collapse Direction:=wdCollapseEnd
            .InsertAfter Text:=" (See page #)"
            .Font.Underline = wdUnderlineNone
          End With
          ActiveDocument.Fields.Add Range:=Rng.Characters(InStr(Rng, "#")), Text:="PAGEREF " & .SubAddress
        End If
      End With
    Next
    Set Rng = Nothing
    Application.ScreenUpdating = True
    Application.ScreenRefresh
    MsgBox ActiveDocument.Hyperlinks.Count & " page numbers have been added.", vbOKOnly
    End Sub
    This version should also run much faster on a document with many hyperlinks.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. The Following User Says Thank You to macropod For This Useful Post:

    MM Sobo (2012-04-30)

  4. New Lounger
    Join Date
    Apr 2012
    Location
    Massachusetts, USA
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you! That does exactly what I need it to do.

  5. Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,349
    Thanks
    0
    Thanked 95 Times in 93 Posts
    Now all you'll need to do is to update your web page ...
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •