Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
How to solve how many lines or items exist in the TOC of a Word (2007)
document using the Basic macro language? |
#2
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
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? |
#3
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
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? |
#4
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
..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" wrote: 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? |
#5
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Sorry, it works OK! I had corrupted my TOCs in my original document.
Tapio "Tapio Marjomaki" wrote: .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" wrote: 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? |
#6
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
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? |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
how can i find all words of a specific character length? | Microsoft Word Help | |||
macro asking for word to find/replace | Microsoft Word Help | |||
Ms Word Find All option in vba Macro | New Users | |||
How do I find my macro files for word so I can import them to my . | Microsoft Word Help | |||
Where can I find Word Macro Examples? | New Users |