From: SoftwareTester on
Using VBA I want to write a Word document.
My headings should NOT have numbering and a TOC will be created (at the top
of the document) after all textual data have been added.

a) I suppose I have to create new styles based on "Heading 1" .... "Heading
5" (using VBA). Is this correct? If so, how can I set numbering off (using
VBA)?
I created:
Function CreateStyleHeadingTask(NameStyle As String) As Word.Style
Set CreateStyleHeadingTask = Nothing
If Not wdDoc Is Nothing Then
With wdDoc
Set CreateStyleHeadingTask = .Styles.Add(Name:=NameStyle,
Type:=wdStyleTypeParagraph)
With CreateStyleHeadingTask
.AutomaticallyUpdate = False
.BaseStyle = "Heading 1"
.NextParagraphStyle = "normal"
With .Font
.Size = 14
.Bold = True
.Color = wdColorRed
End With
End With
End With
End If
End Function

b) How can I insert a TOC (what code) at the top of my document?
From: DaveLett on
Hi,
I recommend that you create a template, define all of your styles there, and
then add a new document based on the template that you created. To add a
table of contents you can use something like the following:

Dim oRng As Range

Set oRng = Selection.Range '''really the top of your document
ActiveDocument.Fields.Add Range:=oRng, Type:=wdFieldTOC

HTH,
Dave