comparing two TOCs

B

BorisS

Okay, I have two tables of contents in two separate files. A few of the
entries in them may be repeats (each is updated regularly, and each will
have different entries each time, with possible different overlaps each time).
I need to, from one of the files, run a macro that will look through every
entry of that file's TOC, then compare each to the TOC of the other file
(preference would be a dialogue way to point to the other file to use, but
could also type into a dialogue, and worst case, can go into the macro and
type in the path for each use...but would prefer to avoid having to go into
macros, as others might be asked to use this who are less proficient), and
finally highlight on the original file any that are found in the other file.
Matches would be exact matches for the entire string except page numbers on
each file would be different.

Thx for any code assistance someone may have.
 
D

Doug Robbins

Something like this might do it (probably needs a bit of refinement - like
deleting all of the page numbers)

Dim Source1 As Document, source2 As Document, target1 As Document, target2
As Document
Set Source1 = ActiveDocument
Set target1 = Documents.Add
Source1.TablesOfContents(1).Range.Fields.Unlink
target1.Range = Source1.TablesOfContents(1).Range
target1.SaveAs "target1.doc"
target1.Close
Source1.Close wdDoNotSaveChanges
With Dialogs(wdDialogFileOpen)
..Show
End With
Set source2 = ActiveDocument
Set target2 = Documents.Add
source2.TablesOfContents(1).Range.Fields.Unlink
target2.Range = source2.TablesOfContents(1).Range
source2.Close wdDoNotSaveChanges
target2.Compare Name:="target1.doc", _
CompareTarget:=wdCompareTargetNew


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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