Update table of Contents Macro - MS Word 2000

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

izzyq

Thread Starter
Joined
Mar 14, 2002
Messages
51
I've recorded a macro to update the Table of contents in my document, but when I run the macro it duplicates the headings. The document is somewhat complicated in that it is an access report that is saved as RIch Text Format and inserted into the word document. There is macro in word that is used to clear all page breaks and another that formats all the main topics as "heading 1". Here is the code to update the TOC as well as the code at formats the headings:


Sub Update_TOC()
'
'
Selection.GoTo What:=wdGoToBookmark, Name:="Table_Of_Contents"
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Fields.Update
End Sub



Sub Heading_1()
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Heading 1")
With Selection.Find
.Text = "#*#*"
.Replacement.Text = "^m"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Heading 1")
With Selection.Find.Replacement.Font
.Bold = True
.Italic = True
End With
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
 
Joined
May 6, 2000
Messages
4,117
Seeing as how no one has responded why don't you let Word 2000 create the table of contents for you.

It is either listed under Insert or Edit I think, has been a while since I used it and I have XP now so I can't check for you.
 

izzyq

Thread Starter
Joined
Mar 14, 2002
Messages
51
Thank you for the reply.
Unfortunately, even when I let word create the table of contents for me it will duplicate the headings.
 
Joined
May 6, 2000
Messages
4,117
If you want, email me the file and I will take a look at it for youi. Sometimes we just over look something because we have been trying so hard.

Did you try the detect and repair in Word, under help click detect and repair.

You probably have already tried this but just in case I will suggest it.

[email protected]

I'll be glad to take a look at it if you want.
 
Joined
May 6, 2000
Messages
4,117
This one is solved.

The solution was to copy and paste a section at a time being careful not to pick up the table of contents formatting. Then after all material was copied to another document we let Microsoft Word create the TOC and all worked well.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top