VBA numbering off headings

S

SoftwareTester

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

DaveLett

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
 

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

Similar Threads

Table of Content 1
White space above heading inconsistently applied 1
Need help modifying code 0
set hanging indent for second TOC 1
TOC problem 0
TOC Help 0
TOC Problem 0
VBA Export to PDF 0

Top