Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Apr 2012
    Location
    Massachusetts, USA
    Posts
    8
    Thanks
    2
    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. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,915
    Thanks
    0
    Thanked 193 Times in 176 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]

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

    MM Sobo (2012-04-30)

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

  6. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,915
    Thanks
    0
    Thanked 193 Times in 176 Posts
    Now all you'll need to do is to update your web page ...
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. #5
    New Lounger
    Join Date
    Apr 2012
    Location
    Massachusetts, USA
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I know that the people who originally replied to my post might not still be online, but I hope someone can help.

    I've been using this macro and loving it. However, now I have a client who wants me to turn over a section of the documentation to the subject matter expert.


    As I mentioned earlier, I used RoboHTML to create the documentation, but the SME won't have RoboHelp and needs to be able to edit the documentation in Word.

    I thought that I could just generate a Word document and turn it over. The SME would then add or change the document as needed, save a copy, and run the page number macro on a copy.

    I tested it first:
    Generated a Word doc from RoboHelp.
    Edited the doc to until I bumped a page.
    Select all, F9. Updated table.
    Saved the file and exited Word.
    Made a copy.
    Ran the macro.

    The PAGEREF still refers to the old page. So I looked at the cross-reference.

    RoboHelp saves its link as a Hyperlink. There's a number after the Hyperlink, which appears again in the PageRef:

    {HYPERLINK \I "adding_a_new_employee_4172"} (page {PAGEREF "adding_a_new_employee_4172" \* MERGEFORMAT})


    I'm using Word 2013.

    Does anyone have any suggestions? I thought that pressing F9 would update the hyperlink, but apparently not.

  8. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,521
    Thanks
    3
    Thanked 143 Times in 136 Posts
    It looks like the macro is only meant to alter a Table of Contents despite the feedback given by the msgbox. It won't do anything for the hyperlink you posted since that hyperlink is NOT pointing at a bookmark which begins with "_Toc"

    The field codes you posted are pointing at a bookmark with the name of "adding_a_new_employee_4172". If you go to Insert > Bookmark and select that particular bookmark and click the Go To button it will show you where that is located. Does that bookmark contain only the content you expected?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  9. The Following User Says Thank You to Andrew Lockton For This Useful Post:

    MM Sobo (2014-03-13)

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
  •