Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    238
    Thanks
    4
    Thanked 1 Time in 1 Post

    Convert hyperlink to page numbered references (200

    I support the Adobe RoboHelp forum where we need some advice from a Word guru. RoboHelp is a program used to generate online help. It can also generate printed documentation using various versions of Word. Where the online help has hyperlinks to other topics, the printed documentation also has hyperlinks. Many people would prefer to see these as cross references including the page numbers. The text of the link can be any text the author inserted in the source files and the target in the online help will be the html file first heading or a bookmark in the file. As part of the generation of the printed version, RoboHelp creates the same links in the printed document.

    Does this sound like something where a macro could be created so that something like "Click here for more information" could be converted to "See page nn for more information"> As indicated above "Click here for more information" could be any string. Ideally the text around "page nn" would be whatever the person running the macro wants but the example given would be OK if that makes things more straightforward.

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    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
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Convert hyperlink to page numbered references (200

    Could you post a small sample document?

  4. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Convert hyperlink to page numbered references (200

    It would be very easy to create links of the form you want, using Word REF fields. It will be important to update the fields when the documented is "printed", as page numbers will depend on features of the destination printer.

    Will the target always be an existing heading, or do you also need to be able to bookmark random text for the target?
    How does the user indicate the target of the cross reference at the moment?

    StuartR

  5. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,491
    Thanks
    3
    Thanked 137 Times in 130 Posts

    Re: Convert hyperlink to page numbered references

    This is relatively straightforward to do and could be made to work along the following lines. This is not completed code but it does most of the work and just needs tinkering to iron out the bugs. As we don't actually know the structure of your files the code is based on looking for hyperlinks with no address which must therefore point to a location within the current file. The subaddress will then hold the location of the relevant bookmark.

    <pre>Dim aHL as Hyperlink, sHL as String, aRng as Range
    For each aHL in ActiveDocument.Hyperlinks
    If aHL.Address = "" then
    sHL = aHL.SubAddress
    Set aRng = aHL.Range
    aRng.InsertAfter " for more information"
    aRng.Fields.Add aHL.Range,, "PageRef " & sHL
    aRng.InsertBefore "See Page "
    aRng.Select
    ActiveDocument.Hyperlinks.Add aRng,, sHL
    End If
    Next aHL</pre>

    Note that the code removes and then recreates a Hyperlink. You may not want the resulting text to be a hyperlink anymore but if you remove the line which adds the hyperlink then the loop will only work on every second hyperlink. You need to reverse the loop (step from last to first) to avoid this issue. You will find samples of relevant code on this forum.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  6. #5
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    238
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Convert hyperlink to page numbered references

    Thanks to all three of you for coming back.

    I will attach a cutdown version of a sample document to this post. I can post a full version direct to anyone interested.

    Using Andrew's code as...

    Sub LinkToCrossRef()
    Dim aHL As Hyperlink, sHL As String, aRng As Range
    For Each aHL In ActiveDocument.Hyperlinks
    If aHL.Address = "" Then
    sHL = aHL.SubAddress
    Set aRng = aHL.Range
    aRng.InsertAfter " for more information"
    aRng.Fields.Add aHL.Range, , "PageRef " & sHL
    aRng.InsertBefore "See Page "
    aRng.Select
    ActiveDocument.Hyperlinks.Add aRng, , sHL
    End If
    Next aHL
    End Sub

    ... it almost does what I want but I think I was not 100% clear.

    First this macro destroys the table of contents in the document but I think that by lifting code from another macro, I can make it work "from this point forward".

    Second and more important, I realise now there are some options as to how this can work.

    Probably the best option is it would be better if the text of the hyperlink remained as a hyperlink. The important bit is adding "See page nn for more information."

    For example, in the online help, typically there will be something like

    "as described in Topic X."

    where Topic X is the hyperlink and will have the hyperlink formatting.

    To make this work for a wider group of users, the creation of the cross reference would leave the hyperlink and add the new cross reference. Thus the end result would be

    "as described in Topic X. See page nn for more information."

    "See page nn for more information." does not have to work as a link done this way. The old hyperlink is there for those wanting that. The page number is for people working from hard copy.

    However, it would be just as acceptable to have both sections working as links or just the page number part as long as the old hyperlink text remains but not formatted as a link.

    I am grateful for the quick responses and Andrew writing a macro. I also hope that I have made things clearer and am not pushing my luck.
    Attached Files Attached Files

  7. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Convert hyperlink to page numbered references

    Try this version:

    Sub InsertPageRefs()
    Dim i As Integer
    Dim h As Hyperlink
    Dim r As Range
    For i = ActiveDocument.Hyperlinks.Count To 1 Step -1
    Set h = ActiveDocument.Hyperlinks(i)
    Set r = h.Range
    If InStr(h.SubAddress, "_Toc") = 0 And h.Address = "" Then
    r.InsertAfter Text:=". See page "
    r.Collapse Direction:=wdCollapseEnd
    r.InsertAfter Text:=" for more information."
    r.Collapse Direction:=wdCollapseStart
    ActiveDocument.Fields.Add Range:=r, Text:="PAGEREF " & h.SubAddress
    End If
    Next i
    End Sub

    It inserts some text and a page reference after the hyperlinks, and it leaves the TOC intact (it checks for hyperlinks whose target contains _Toc).

  8. #7
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    238
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Convert hyperlink to page numbered references

    Hans

    Absolutely perfect! I will shortly be posting this on my site which gets about 200 hits a day from technical authors around the world. I will of course be giving you credit for this and I am always telling people this is the best Word forum I have ever encountered.

    Hans thanks for once again assisting me but this time many more people.

    My thanks also to Andrew for his macro. It did not do quite what I wanted but that is only because it made me realise I wanted something other than what I had said I wanted. A trick I learned from my wife!

    Guys. Thank you.

Posting Permissions

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