Is Insertion Point in Table of Contents (TOC)?

J

Jezebel

Dim pField as Word.Field
Dim pTOC as Word.Range

'First, find the TOC --
For each pField in ActiveDocument.Fields
if pField.Type = wdFieldTOC then
set pTOC = pField.Result
exit for
end if
Next

'Now check if the selection is inside it
If Selection.Start >= pTOC.Start and Selection.End <= pTOC.End then
... yes it is


Note that there's an ambiguity about 'selection within the TOC' -- do you
mean wholly contained within, or merely includes at least some of it? (eg
you can select a range with the start within and the end outside, or vice
versa).
 
G

George Lee

Thanks. It works. Also, I was determining this for the insertion point or the
start of the range. The trick was to find this table in the first place.

However, it seems different than what I was expecting. I used the .Selection
information to see if either the Table.Count or Fields.Count equaled 1. In
both cases, the count was zero.
 
J

Jezebel

Table.Count returns zero because a TOC is not a "table" (of the sort that
you get from Table > Insert). I don't know why Fields.Count returns zero in
this case.

It doesn't help here, but the Information() function tells you if the
insertion point is within a true table.
 

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