Class AutoCaption (Word VBA)

The class AutoCaption represents a single caption that can be automatically added when items such as tables, pictures, or OLE objects are inserted into a document. The AutoCaption object is a member of the AutoCaptions collection. The AutoCaptions collection contains all the captions listed in the AutoCaption dialog box.

Set

To use a AutoCaption class variable it first needs to be instantiated, for example

Dim acn as AutoCaption
Set acn = AutoCaptions(Index:=1)

The following procedures can be used to set variables of type AutoCaption: AutoCaptions.Item and Application.AutoCaptions

For Each

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

Dim acn As AutoCaption
For Each acn In AutoCaptions
	
Next acn

AutoInsert

True if a caption is automatically added when the item is inserted into a document.

AutoCaptions("Microsoft Word Table").AutoInsert = True 
Selection.Collapse Direction:=wdCollapseStart 
ActiveDocument.Tables.Add Range:=Selection.Range, _ 
 NumRows:=2, NumColumns:=2

CaptionLabel

Returns or sets the caption label ("Figure," "Table," or "Equation," for example) of the specified caption. Read/write Variant.

This property can be set to a string or a WdCaptionLabelID constant.

Dim acLoop As AutoCaption 
 
For Each acLoop In AutoCaptions 
 If acLoop.AutoInsert = True Then MsgBox acLoop.Name _ 
 & vbCr & "Label = " & acLoop.CaptionLabel.Name 
Next acLoop

Index

Returns a Long that represents the position of an item in a collection.

Dim lngIndex As Long
lngIndex = AutoCaptions(1).Index

Name

Returns or sets the name of the specified object.

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

Parent

Returns an object that represents the parent object of the specified AutoCaption object.

Dim objParent As Object
Set objParent = AutoCaptions(1).Parent

AutoCaptions.CancelAutoInsert

Prevents Word from automatically adding captions to any type of item.

AutoCaptions.CancelAutoInsert

AutoCaptions.Count

Returns the number of items in the AutoCaptions collection.

Dim lngCount As Long
lngCount = AutoCaptions.Count

AutoCaptions.Item

Returns an individual AutoCaption object in a collection.

Syntax : expression.Item (Index)

Index: The individual object to be returned. Can be a Long indicating the ordinal position or a String representing the name of the individual object.

Dim acn As AutoCaption
Set acn = AutoCaptions(Index:=1)

AutoCaptions.Parent

Returns an object that represents the parent object of the specified AutoCaptions collection.

Dim objParent As Object
Set objParent = AutoCaptions.Parent