How to know the document already add table of content

M

moonhkt

Hi All


Word 2007.

How to know the document already add table of content ? if exist, how to refresh the table of content ?

moonhkt
 
S

Stefan Blom

The following macro will update all tables of contents in the active
document:

Sub UpdateAllTablesOfContents()
Dim toc As TableOfContents
For Each toc In ActiveDocument.TablesOfContents
toc.Update
Next toc
End Sub

If you need assistance, see http://www.gmayor.com/installing_macro.htm.

Stefan Blom
Microsoft Word MVP
 
M

moonhkt

The following macro will update all tables of contents in the active
document:

Sub UpdateAllTablesOfContents()
Dim toc As TableOfContents
For Each toc In ActiveDocument.TablesOfContents
toc.Update
Next toc
End Sub

If you need assistance, see http://www.gmayor.com/installing_macro.htm.

Stefan Blom
Microsoft Word MVP

Thank. But how to check document already have TOC ?
 
S

Stefan Blom

The macro will run without problems even if there are no TOCs in the
document. However, if you want to test for the presence of a TOC (in
some other context), you can use the Count property of the
TablesOfContents collection:

If ActiveDocument.TablesOfContents.Count > 0 Then
'code goes here
End If

Stefan Blom
Microsoft Word MVP
 
M

moonhkt

Stefan Blomæ–¼ 2012å¹´7月4日星期三UTC+8下åˆ8時07分37秒寫é“:
The macro will run without problems even if there are no TOCs in the
document. However, if you want to test for the presence of a TOC (in
some other context), you can use the Count property of the
TablesOfContents collection:

If ActiveDocument.TablesOfContents.Count > 0 Then
'code goes here
End If

Stefan Blom
Microsoft Word MVP

Thank. It works.
 

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