Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Word Style in a document for TOC generation

Status
Not open for further replies.

bntwillis

Technical User
Joined
Jan 17, 2004
Messages
5
Location
US
Hi All,
Using WIndows 2000 with Word 2002.
We have a vba app that autogenerates a word doc. The app assumes all the heading styles in the doc will be Heading 1-9 (the default word headings). This is fine except when we generate the toc we want there to be an appendix section. I have changed the styles in the template we used so the section headings for the appendix now get generated correctly in the toc. The problem is the data being populated under the toc is not being numbered correctly in the toc. The content is being inserted and formatted assuming the Heading 1-9 styles. How can I programaticly change the content so that it is formatted with a different style?
Currently we use code that does the following:
RenderModelElement _
objModelElement, "", _
FSAppConfig.cnstCSCI_MISC_HEADING, _
intHeadingLevel + 1
I am new to VBA (this problem was handed to me recently) and would appreciate any guidance available.
 
Have you tried the macro recorder ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Yes I have. It is simple as you would imagine:
Selection.Style = ActiveDocument.Styles("Appendix 2")

But for some reason I never get the Appendix 2 style when the doc is generated.

At one point I thought I found the answer when I realized the Appendix 2 style is based on Normal, Body 1 word style, but still my toc is looking for the appendix 2 style not the Normal, Body 1. And unfortunalty Normal Body 1 is used in other places in the document so I don't want the toc to look for that.

Thanks for the suggestion.
 
So your problem is, having your "Appendix" style(s) implemented?
For such a case, I store special styles in a template at a fixed path (here: C:\App\Appendices.dot) and then copy the templates to my ActiveDocument during Macro execution:
Code:
Dim TheWindow As String, i as Integer
TheWindow = ActiveDocument.FullName
For i=1 to 9 [green]'Number of Appendix styles (Appendix1..Appendix9)[/green]
    Application.OrganizerCopy Source:="C:\App\Appendices.dot", _
    Destination:=TheWindow, Name:="Appendix" & i, Object:= _
    wdOrganizerObjectStyles
Next i

Hope this helps,
Andy


[blue]The last voice we will hear before the world explodes will be that of an expert saying:
"This is technically impossible!" - Sir Peter Ustinov[/blue]
andreas.galambos@bowneglobal.de
HP:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top