Sections object (Publisher)
A collection of all the Section objects in the document.
Remarks
Use Item (index), where (index) is the index number, to return a single Section object. Using Sections (index), where (index) is the index number, will also return a single Section object.
Use Count to return the number of sections in the publication.
Use Add (StartPageIndex), where StartPageIndex is the index number of the page, to return a new section added to a document. A "Permission denied" error is returned if the page already contains a section head.
Use Section.Delete (index), where (index) is the index number, to delete the specified section from the document. A "Permission denied" error is returned if an attempt is made to delete the first section.
Example
The following example sets the number format and the starting number for the first section of the active document.
With ActiveDocument.Sections.Item(1)
.PageNumberFormat = pbPageNumberFormatArabic
.PageNumberStart = 1
End With
The following example continues the numbering from the previous section for the second section in the active document.
ActiveDocument.Sections(2).ContinueNumbersFromPreviousSection=True
The following example displays the number of sections in the first open document.
MsgBox Documents(1).Sections.Count
The following example adds a new section to the second page of the active document.
Dim objSection As Section
Set objSection = ActiveDocument.Sections.Add(StartPageIndex:=2)
The following example deletes all the sections of the active document except the first one.
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.
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
Methods
Properties
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.