Share via


Sections Object

Publisher Developer Reference

A collection of all the Section objects in the document.

Example

Use Sections.Item(index) where index is the index number, to return a single Section object. The following example sets the number format and the starting number for the first section of the active document.

Visual Basic for Applications
  With ActiveDocument.Sections.Item(1)
    .PageNumberFormat = pbPageNumberFormatArabic
    .PageNumberStart = 1
End With

Using Sections(index) where index is the index number, will also return a single Section object. The following example sets continues the numbering from the previous section for the second section in the active document.

Visual Basic for Applications
  ActiveDocument.Sections(2).ContinueNumbersFromPreviousSection=True

Use Sections.Count to return the number of sections in the publication. The following example display the number of sections in the first open document.

Visual Basic for Applications
  MsgBox Documents(1).Sections.Count

Use Sections.Add(StartPageIndex) where StartPageIndex is the index number of the page, to reutrn a new section added to a document. A "Permission denied." error will be returned if the page already contains a section head. The following example adds a new section to the second page of the active document.

Visual Basic for Applications
  Dim objSection As Section
Set objSection = ActiveDocument.Sections.Add(StartPageIndex:=2)

Use Sections(index).Delete where index is the index number, to delete the specified section from the document. A "Permission denied" error will be returned if an attempt is made to delete the first section. The following example deletes all of the sections of the active document except the first one.

Aa436419.vs_note(en-us,office.12).gif  Note
The iteration is from the last to the first to avoid a "Subscript out of range." error when accessing a deleted section in the Sections collection.
Visual Basic for Applications
  Dim i As Long
For i = ActiveDocument.Sections.Count To 1 Step -1
    If i = 1 Then Exit For
    ActiveDocument.Sections(i).Delete
Next i

See Also