View Single Post
  #6   Report Post  
Posted to microsoft.public.word.tables
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default How to find out the length the TOC by a Word 2007 macro?

Well spotted Stefan!

So the line:
..TablesOfContents(i).Range.Paragraphs.Count & " Entries."
should read:
..TablesOfContents(i).Range.Paragraphs.Count -1 & " Entries."

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

"Stefan Blom" wrote in message ...
Maybe I'm missing something, but the macro seems to count the paragraph in
which the TOC field is located too? In other words, you would have to use
.Count - 1.

--
Stefan Blom
Microsoft Word MVP


"macropod" wrote in message ...
Hi Tapio,

Here's one way to count all TOCs in the active document:
Sub Count_TOC_Entries()
Dim i As Integer
With ActiveDocument
If .TablesOfContents.Count 0 Then
For i = 1 To .TablesOfContents.Count
MsgBox "TOC " & i & " in """ & .Name & """ has " & _
.TablesOfContents(i).Range.Paragraphs.Count & " Entries."
Next i
Else
MsgBox "No TOCs found in " & .Name
End If
End With
End Sub

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

"Tapio Marjomaki" Tapio wrote in
message ...
How to solve how many lines or items exist in the TOC of a Word (2007)
document using the Basic macro language?