T
Tapio Marjomaki
How to solve how many lines or items exist in the TOC of a Word (2007)
document using the Basic macro language?
document using the Basic macro language?
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 said:How to solve how many lines or items exist in the TOC of a Word (2007)
document using the Basic macro language?
macropod said: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 said:How to solve how many lines or items exist in the TOC of a Word (2007)
document using the Basic macro language?
Tapio Marjomaki said:.TablesOfContents.Count = 0 every time I run my macro though there's TOC ...
(of three items in my case) ? It should return 3 but returns 0.
Thanks anyway, Tapio
macropod said: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 said:How to solve how many lines or items exist in the TOC of a Word (2007)
document using the Basic macro language?
Stefan Blom said: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
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 said:How to solve how many lines or items exist in the TOC of a Word (2007)
document using the Basic macro language?