Getting and fixing the Hyperlinks created by a Table of Contents

B

BBM

Hi,

I have a Word document with a Table of Contents in it. I understand from
other posts on this forum that Word automatically inserts Hyperlink fields
into the ToC when it is created to let the user branch from the ToC to the
Heading Text using Ctrl + Click.

The problem is this. My document references other Linked Files (Word
files), and these files contain Heading text that generate ToC entries. When
I first open the document with the ToC in it, each ToC entry has

Error! Bookmark not defined

in place of the page number. If I refresh the ToC (using F9), it corrects
itself. I'd like to fix this (the error not the correction!).

A further complication... This document (and the linked documents) are meant
to be downloaded from the server to a user's PC. The main document (the one
with the ToC) has a VBA sub (that I downloaded from this forum), that
converts the absolute Linked File names that Word creates to names that work
on the User's PC based on the folder the files are downloaded to. This is
working fine. I can download the whole set of docs to any folder and they
properly reference each other. Right now, the only references that get
changed by the code are for fields of type wdFieldIncludeText. I don't think
this code is causing any problems, but it could be that it's not doing enough
(i.e. the ToC hyperlink fields need their references changed too).

My questions:
1) Is the TOC using Hyperlinks or Bookmarks to branch to the Heading from
the ToC? They look to the user like Hyperlinks (Hover Help shows Ctrl +
Click to branch), but it would make sense for them to be bookmarks since
you're moving within the same document. Is this the reason I'm getting an
error message about bookmarks?
2) What is the wdFieldType of the field that Word is inserting for the TOC
branch feature, and where is the file location/name (or bookmark name) of the
hyperlinked/ bookmarked file in the field?
3) Can I just turn off the ToC Hyperlink feature somehow?

Thanks. And sorry for the rambling question.

BBM
 
J

Jezebel

When you create a TOC, Word bookmarks each referenced heading. You can see
these bookmarks if you display the Insert Bookmark dialog and check the
'Hidden bookmarks' checkbox -- you'll see a heap of bookmarks with names
like _toc123456789.

The 'Error! Bookmark not defined' message means that those bookmarks have
been removed (either directly, or by deleting the heading) since the
bookmark was last updated.

Internally, the TOC, if it includes the \h switch, contains a hyperlink
field (wdFieldHyperlink) for each text entry (with the \l switch, to
hyperlink to the bookmark), and a page ref field (wdFieldPageRef) for the
page number.

You can turn off the TOC hyperlinking by displaying the field code and
removing the \h switch.


You shouldn't need to run any VBA to convert hyperlinks in the downloaded
document: if you enter the hyperlink references as relative paths, they
remain that way. The confusing bit is only that Word's screentip always
displays the fully resolved path; but if you check the hyperlink's .Address
property you'll see that it is still stored as the original relative path.
 
B

BBM

Thanks for the information.

I haven't had any luck entering a relative path to the linked documents.
All my linked documents are in the same folder as the document with the ToC.
But entering just the file name with the extension does not work. What
should a relative path to a word document in the same folder look like
(spaces embedded in the file name BTW)?

As far as I can tell, Insert Hyperlink creates a relative path (although one
with "%20%" seemingly replacing all the blanks (BTW I tried keying one of my
documents paths in the insert file dialog like this with no success either).
Insert File and then selecting link creates an absolute path.

Do you have any ideas about how the bookmarks could get removed? I
literally load the document into Word, rebuild the TOC, save the document,
and when I re-load it it's clobbered again.

Thanks again for your help.

BBM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top