Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-11-2020, 04:04 PM
tlafferty tlafferty is offline Use VBA to insert cross references by looping through entire document from insertion point to end Windows 10 Use VBA to insert cross references by looping through entire document from insertion point to end Office 2016
Novice
Use VBA to insert cross references by looping through entire document from insertion point to end
 
Join Date: May 2020
Posts: 1
tlafferty is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 05-11-2020, 05:09 PM
macropod's Avatar
macropod macropod is offline Use VBA to insert cross references by looping through entire document from insertion point to end Windows 7 64bit Use VBA to insert cross references by looping through entire document from insertion point to end Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 05-11-2020, 11:09 PM
Guessed's Avatar
Guessed Guessed is offline Use VBA to insert cross references by looping through entire document from insertion point to end Windows 10 Use VBA to insert cross references by looping through entire document from insertion point to end Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
Reply

Tags
cross-reference, vba, word 16.



Similar Threads
Thread Thread Starter Forum Replies Last Post
Use VBA to insert cross references by looping through entire document from insertion point to end 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
Use VBA to insert cross references by looping through entire document from insertion point to end Move Insertion Point with VBA Grasor Word VBA 2 10-11-2016 08:50 PM
Use VBA to insert cross references by looping through entire document from insertion point to end 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:04 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft