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
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