Word VBA: Getting the Current Section Number

This Word VBA macro displays the current section number.

Macro Example

Sub GetCurrentSectionNumber()

  MsgBox Selection.Information(wdActiveEndSectionNumber)

End Sub

Description

[Application.]Selection

  Selection...

The Application.Selection property returns the Selection object that represents a selected range or the insertion point.

obj-Word-Application-Selection

The Selection property is a member of the Word.Global class, so we can omit the Application property.

obj-Word-Global-Selection

Selection.Information

  Selection.Information...

The Selection.Information property returns information about the specified selection.

obj-Word-Selection-Information

Const: wdActiveEndSectionNumber

  Selection.Information(wdActiveEndSectionNumber)

We can get the current section number by setting the const: wdActiveEndSectionNumber to the parameter of the Selection.Information property.

obj-Word-WdInformation-wdActiveEndSectionNumber

MsgBox function

The code: Selection.Information(wdActiveEndSectionNumber) is set to the parameter of a MsgBox function.

  MsgBox Selection.Information(wdActiveEndSectionNumber)

So a message box shows the current section number.

Sub GetCurrentSectionNumber()

  MsgBox Selection.Information(wdActiveEndSectionNumber)

End Sub

Properties

http://www.relief.jp/itnote/archives/word-vba-getting-section-number.php

Apply To

  • Word 2013
  • Word 2010
  • Word 2007