Problem with Table of contents and styles

A

Ambarish

Hi,
I am developing a macro which does the following:
a. Copy multiple documents in a single document.
b. Have separate table of contents (TOC) for each document copied.
i.e. If I copy 10 documents in a single document, say doc1.doc,
doc1.doc will have 10 TOCs for the 10 documents copied.

I am able to do the part (a).
What I am planning to do for (b) is,
1. Search for the text 'chapter1', 'chapter2' etc in the document
doc1.doc(to build the TOC). I am doing this with .Find
2. As soon as I get 'Chapter1', place a bookmark and replace the style
with a custom style. Do this till the end of the document.
3. Find the bookmark, go to that location and insert the TOC. The TOC
will be built on the custom style.

I am stuck at point 2. I am able to find the desired text, but when i
try to change the style, it is not changing.
Here is the code:

Dim WordApp as Word.Application
With WordApp.Selection.Find
.Forward = True
.MatchWholeWord = True
.MatchCase = False
.Execute FindText:="Ambarish"

If .Found = True Then
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Style = ActiveDocument.Styles("Ambarish")
End If
End With

Style "Ambarish" is present in the document which is a paragraph
style.

I also tried another approach. Instead of finding the text 'Chapter1',
I tried to search on the style "Normal + Tahoma, 16 pt, Bold". But,
when I printed the available styles and font, I only got "Normal",
"Times New Roman", font 10.
What can be the reason for this, and how do I find the style?

Can anybody help me on this issue?
Thanks in advance.

Regards,
Ambarish
 
J

Jonathan West

Take a diiferent approach.

Mark each inserted document with a different bookmark. Set the TOC for each
document so it references only the headings within that document by adding a
\b switch with the bookmark name.
 
J

Jay Freedman

Hi Ambarish,

I'm going to sidestep the entire issue of changing styles. Instead I'll
point out that you can set a bookmark to cover an entire chapter, and then
insert a \b switch in a TOC field to make it extract headings only from that
bookmark. You can create as many TOC fields as you like, each referring to a
different bookmark (chapter).

Read "A partial table of contents" in
http://www.word.mvps.org/FAQs/Formatting/TOCSwitches.htm for further
discussion.

Also, it will probably be easier to insert each bookmark and its TOC
immediately after the macro copies that chapter, rather than waiting until
all the chapters are present and then using Find to locate the chapter
titles.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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