How do tell if the insertion point in a table of contents (TOC)?

Re: Is Insertion Point in Table of Contents (TOC)? by Jezebel

Jezebel
Wed Oct 19 16:27:29 CDT 2005


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).






"George Lee" <GeorgeLee@discussions.microsoft.com> wrote in message
news:8B9D2F88-6D26-466E-B755-FA9BD00D91C3@microsoft.com...
> How do tell if the insertion point in a table of contents (TOC)?



Re: Is Insertion Point in Table of Contents (TOC)? by GeorgeLee

GeorgeLee
Fri Oct 21 10:23:01 CDT 2005

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.

"Jezebel" wrote:

>
> 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).
>
>
>
>
>
>
> "George Lee" <GeorgeLee@discussions.microsoft.com> wrote in message
> news:8B9D2F88-6D26-466E-B755-FA9BD00D91C3@microsoft.com...
> > How do tell if the insertion point in a table of contents (TOC)?
>
>
>

Re: Is Insertion Point in Table of Contents (TOC)? by Jezebel

Jezebel
Sat Oct 22 18:14:13 CDT 2005

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.




"George Lee" <GeorgeLee@discussions.microsoft.com> wrote in message
news:0A1CEECC-7F35-44FB-AE88-A616A887A26B@microsoft.com...
> 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.
>
> "Jezebel" wrote:
>
>>
>> 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).
>>
>>
>>
>>
>>
>>
>> "George Lee" <GeorgeLee@discussions.microsoft.com> wrote in message
>> news:8B9D2F88-6D26-466E-B755-FA9BD00D91C3@microsoft.com...
>> > How do tell if the insertion point in a table of contents (TOC)?
>>
>>
>>