Class CaptionLabel (Word VBA)

The class CaptionLabel represents a single caption label. The CaptionLabel object is a member of the CaptionLabels collection. The items in the CaptionLabels collection are listed in the Label box in the Caption dialog box. To use a CaptionLabel class variable it first needs to be instantiated, for example


Dim cll as CaptionLabel
Set cll = CaptionLabels(Index:=1)

For Each

Here is an example of processing the CaptionLabel items in a collection.


Dim cll As CaptionLabel
For Each cll In CaptionLabels
	
Next cll

BuiltIn

True if the specified caption label is one of the built-in caption labels in Word.

You can specify built-in styles across all languages by using the WdBuiltinStyle constants or within a language by using the style name for the language version of Word. For example, if you specify U.S. English in your Microsoft Office language settings, the following statements are equivalent:


ActiveDocument.Styles(wdStyleHeading1) 
ActiveDocument.Styles("Heading 1")

ChapterStyleLevel

Returns or sets the heading style that marks a new chapter when chapter numbers are included with the specified caption label.

The number 1 corresponds to Heading 1, 2 corresponds to Heading 2, and so on. The IncludeChapterNumber property must be set to True for chapter numbers to be included with caption labels.


With CaptionLabels(wdCaptionTable) 
 .IncludeChapterNumber = True 
 .ChapterStyleLevel = 2 
End With

Delete

Deletes the specified caption label.


CaptionLabels(1).Delete

ID

Returns a WdCaptionLabelID constant that represents the type for the specified caption label if the BuiltIn property of the CaptionLabel object is True. Possible return values are wdCaptionEquation - Equation, wdCaptionFigure - Figure, wdCaptionTable - Table.


For Each cl In CaptionLabels 
 If cl.BuiltIn = True Then MsgBox cl.Name & " " & cl.ID 
Next cl

IncludeChapterNumber

True if a chapter number is included with page numbers or a caption label.


With CaptionLabels(wdCaptionFigure) 
 .IncludeChapterNumber = True 
 .ChapterStyleLevel = 2 
 .NumberStyle = wdCaptionNumberStyleUppercaseLetter 
End With 
Selection.InsertCaption Label:="Figure", Title:=": History"

Name

Returns the name of the specified object.


Dim strName As String
strName = CaptionLabels(1).Name

NumberStyle

Returns or sets the number style for the CaptionLabel object. Here you can find possible values for WdCaptionNumberStyle.

Some of the constants listed above may not be available to you, depending on the language support (U.S. English, for example) that you've selected or installed.


CaptionLabels(wdCaptionFigure).NumberStyle = _ 
 wdCaptionNumberStyleUppercaseLetter 
Selection.Collapse Direction:=wdCollapseEnd 
Selection.InsertCaption Label:=wdCaptionFigure

Position

Returns or sets the position of caption label text. Possible return values are wdCaptionPositionAbove - The caption label is added above, wdCaptionPositionBelow - The caption label is added below.


CaptionLabels(1).Position = wdCaptionPositionAbove

Separator

Returns or sets the character between the chapter number and the sequence number. Possible return values are wdSeparatorColon - A colon, wdSeparatorEmDash - An emphasized dash, wdSeparatorEnDash - A standard dash, wdSeparatorHyphen - A hyphen, wdSeparatorPeriod - A period.


With CaptionLabels("Figure") 
 .Separator = wdSeparatorColon 
 .IncludeChapterNumber = True 
End With 
Selection.InsertCaption "Figure"