Class List (Word VBA)

The class List represents a single list format that's been applied to specified paragraphs in a document. The List object is a member of the Lists collection. To use a List class variable it first needs to be instantiated, for example


Dim lst as List
Set lst = ActiveDocument.Lists(Index:=1)

For Each

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


Dim lst As List
For Each lst In ActiveDocument.Lists
	
Next lst

ApplyListTemplate

Applies a set of list-formatting characteristics to the specified ListFormat object.

ApplyListTemplate (ListTemplate, ContinuePreviousList, DefaultListBehavior)


Set myDoc = ActiveDocument 
Set myRange = myDoc.Range( _ 
 Start:= myDoc.Paragraphs(3).Range.Start, _ 
 End:=myDoc.Paragraphs(6).Range.End) 
If myRange.ListFormat.ListType = wdListNoNumbering Then 
 myRange.ListFormat.ApplyListTemplate _ 
 ListTemplate:=ListGalleries(wdOutlineNumberGallery) _ 
 .ListTemplates(4) 
End If

Arguments

The following argument is required

ListTemplate (ListTemplate) - The list template to be applied.

Optional arguments

The following arguments are optional

ContinuePreviousList (Boolean) - True to continue the numbering from the previous list; False to start a new list.

DefaultListBehavior (WdDefaultListBehavior) - Sets a value that specifies whether Microsoft Word uses new web-oriented formatting for better list display. Can be either of the following WdDefaultListBehavior constants: wdWord8ListBehavior (use formatting compatible with Microsoft Word 97) or wdWord9ListBehavior (use web-oriented formatting). For compatibility reasons, the default constant is wdWord8ListBehavior, but in new procedures you should use wdWord9ListBehavior to take advantage of improved web-oriented formatting with respect to indenting and multilevel lists.

Possible return values are wdWord10ListBehavior - Use formatting compatible with Microsoft Word 2002, wdWord8ListBehavior - Use formatting compatible with Microsoft Word 97, wdWord9ListBehavior - Use Web-oriented formatting as introduced in Microsoft Word 2000.

ApplyListTemplateWithLevel

Applies a set of list-formatting characteristics, optionally for a specified level.

ApplyListTemplateWithLevel (ListTemplate, ContinuePreviousList, DefaultListBehavior, ApplyLevel)


Set myDoc = ActiveDocument 
Set myRange = myDoc.Range( _ 
 Start:= myDoc.Paragraphs(3).Range.Start, _ 
 End:=myDoc.Paragraphs(6).Range.End) 
If myRange.ListFormat.ListType = wdListNoNumbering Then 
 myRange.ListFormat.ApplyListTemplate _ 
 ListTemplate:=ListGalleries(wdOutlineNumberGallery) _ 
 .ListTemplates(4) 
End If

Arguments

The following argument is required

ListTemplate (ListTemplate) - The list template to be applied.

Optional arguments

The following arguments are optional

ContinuePreviousList (Boolean) - True to continue the numbering from the previous list; False to start a new list.

DefaultListBehavior (WdDefaultListBehavior) - Sets a value that specifies whether Microsoft Word uses new Web-oriented formatting for better list display. Can be either of the following WdDefaultListBehavior constants: wdWord8ListBehavior (use formatting compatible with Microsoft Word 97) or wdWord9ListBehavior (use Web-oriented formatting). For compatibility reasons, the default constant is wdWord8ListBehavior, but in new procedures you should use wdWord9ListBehavior to take advantage of improved Web-oriented formatting for indenting and multiple-level lists.

Possible return values are wdWord10ListBehavior - Use formatting compatible with Microsoft Word 2002, wdWord8ListBehavior - Use formatting compatible with Microsoft Word 97, wdWord9ListBehavior - Use Web-oriented formatting as introduced in Microsoft Word 2000.

ApplyLevel (Long) - The level to which the list template is to be applied.

CanContinuePreviousList

Returns a WdContinue constant (wdContinueDisabled, wdResetList, or wdContinueList) that indicates whether the formatting from the previous list can be continued. Possible return values are wdContinueDisabled - Formatting cannot continue from the previous list, wdContinueList - Formatting can continue from the previous list, wdResetList - Numbering can be restarted.

This method returns the state of the Continue previous list and Restart numbering options in the Bullets and Numbering dialog box for a specified list format. To change the settings of these options, set the ContinuePreviousList argument of the ApplyListTemplate method.

CanContinuePreviousList (ListTemplate)

ListTemplate: A list template that's been applied to previous paragraphs in the document.


Dim lfTemp As ListFormat 
Dim intContinue As Integer 
 
Set lfTemp = Selection.Range.ListFormat 
 
intContinue = lfTemp.CanContinuePreviousList( _ 
 ListTemplate:=lfTemp.ListTemplate) 
If intContinue <> wdContinueDisabled Then 
 lfTemp.ApplyListTemplate _ 
 ListTemplate:=lfTemp.ListTemplate, _ 
 ContinuePreviousList:=True 
End If

ConvertNumbersToText

Changes the list numbers and LISTNUM fields in the specified List object.

ConvertNumbersToText (NumberType)

CountNumberedItems

Returns the number of bulleted or numbered items and LISTNUM fields in the specified List object.

CountNumberedItems (NumberType, Level)


Selection.Range.ListFormat.ApplyListTemplate _ 
    ListTemplate:=ListGalleries(wdNumberGallery).ListTemplates(2) 
Msgbox ActiveDocument.CountNumberedItems

Arguments

Optional arguments

The following arguments are optional

NumberType - WdNumberType

Possible return values are wdNumberAllNumbers - Default value for all other cases, wdNumberListNum - Default value for LISTNUM fields, wdNumberParagraph - Preset numbers you can add to paragraphs by selecting a template in the Bullets and Numbering dialog box.

Level - Byte

ListParagraphs

Returns a ListParagraphs collection that represents all the numbered paragraphs in the list, document, or range.

For information about returning a single member of a collection, see Returning an object from a collection.


For Each mypara In ActiveDocument.Lists(2).ListParagraphs 
 mypara.Range.Underline = wdUnderlineDouble 
Next mypara

Range

Returns a Range object that represents the portion of a document that is contained in the specified object.


Dim rngRange As Range
Set rngRange = ActiveDocument.Lists(1).Range

RemoveNumbers

Removes numbers or bullets from the specified list.

RemoveNumbers (NumberType)

NumberType: The type of number to be removed.


ActiveDocument.Lists(1).RemoveNumbers

SingleListTemplate

True if the entire list uses the same list template.


Dim booSingleListTemplate As Boolean
booSingleListTemplate = ActiveDocument.Lists(1).SingleListTemplate

StyleName

Returns the name of the style applied to the specified AutoText entry.


Set myentry = NormalTemplate.AutoTextEntries.Add(Name:="rsvp", _ 
 Range:=Selection.Range) 
MsgBox myentry.StyleName