Sections コレクション オブジェクト
Microsoft Word Visual Basic リファレンス |
Sections コレクション オブジェクト
複数のオブジェクト Sections 複数のオブジェクト |
選択範囲、指定範囲、または文書の Section オブジェクトのコレクションです。
使い方
Sections プロパティを使用して Sections コレクションを取得します。次の使用例は、作業中の文書の最後のセクションの末尾に文字列を挿入します。
With ActiveDocument.Sections.Last.Range
.Collapse Direction:=wdCollapseEnd
.InsertAfter "end of document"
End With
Add または InsertBreak メソッドを使用して、新しいセクションを文書に追加します。次の使用例は、作業中の文書の先頭に新しいセクションを追加します。
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
ActiveDocument.Sections.Add Range:=myRange
myRange.InsertParagraphAfter
次の使用例は、作業中の文書のセクション数を表示し、選択範囲の最初の段落の前にセクション区切りを追加し、再びセクション数を表示します。
MsgBox "セクション数: " & ActiveDocument.Sections.Count
Selection.Paragraphs(1).Range.InsertBreak _
Type:=wdSectionBreakContinuous
MsgBox "セクション数: " & ActiveDocument.Sections.Count
Sections(index) を使用して 1 つの Section オブジェクトを取得します。index にはインデックス番号を指定します。次の使用例は、作業中の文書の最初のセクションで左右のページ余白を設定します。
With ActiveDocument.Sections(1).PageSetup
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
End With