|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Use VBA to insert cross references by looping through entire document from insertion point to end
I'd like to use VBA to insert a cross reference link to the table of contents for every time it finds the text "Click to Return to Table of Contents"
This can't be an ordinary hyperlink to a place in the document, because when I save as PDF, it breaks the link. If I insert a cross reference, it works fine when I convert to PDF. The table of contents only includes heading 1, and does not include the words "Table of Contents" as part of the table. I have manually inserted a bookmark named "TableofContents" at the top of the table. The text the bookmark displays is "Table of Contents" and it is to this point I need to link. |
#2
|
||||
|
||||
If you save a document as a PDF and use the 'Create bookmarks using Headings' option, the bookmarks pop-out in Adobe Reader functions as an expandable Table of Contents.
Anything fancier would require you to bookmark both the Table of Contents and every Heading in the document, so your save-as could use the 'Create bookmarks using bookmarks' option. As for your "Click to Return to Table of Contents" requirement, all you need do is create the cross-reference once, then copy that to the clipboard and use Find/Replace to replace all the other instances with the clipboard contents. No code required.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
What is the cross-reference anchor text showing? If it is a cross-reference, that would imply that the words "Click to Return to Table of Contents" need to appear at the top of the TOC. A hyperlink is more flexible in that it doesn't need to be the same words as the location it is pointing to. If your hyperlinks are breaking, it is likely that your TOC field is being updated as part of the save and that the bookmarked range is inside the TOC field instead of being placed immediately in front of the TOC.
Paul's suggestion of using Find and Replace to create the multitude of links is by far the easiest way to do what you are asking for. Placing these links all over the document for the express purpose of being able to bounce back to the TOC is not as quick as using the GoBack keyboard command. I would recommend you also teach users to press Alt-Left Arrow to return to the last clicked hyperlink.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
Tags |
cross-reference, vba, word 16. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Is there a way to summarise all bookmarks and cross references used in a Word document? | Training | Word VBA | 1 | 11-09-2017 12:06 AM |
Move Insertion Point with VBA | Grasor | Word VBA | 2 | 10-11-2016 08:50 PM |
cross references and dynamic numbering in a document | JJ_Writing | Word | 4 | 11-05-2015 02:19 AM |
Updating document causes change lines on all cross references. :( | garybeck | Word | 2 | 05-08-2015 09:15 PM |
Convert manual cross references in footnotes to other footnotes to automatic cross references | ghumdinger | Word VBA | 7 | 11-20-2014 11:47 PM |