CustomLabels Collection Object

Word Developer Reference

A collection of CustomLabel objects available in the Label Options dialog box. This collection includes custom labels of all printer types (dot-matrix, laser, and ink-jet printers).

Remarks

Use the CustomLabels property to return the CustomLabels collection. The following example displays the number of available custom labels.

Visual Basic for Applications
  MsgBox Application.MailingLabel.CustomLabels.Count

Use the Add method to create a custom label. The following example adds a custom mailing label named "My Label" and sets the page size.

Visual Basic for Applications
  Set ML = _
    Application.MailingLabel.CustomLabels.Add(Name:="My Labels", _
    DotMatrix:=False)
ML.PageSize = wdCustomLabelA4

Use CustomLabels(Index), where Index is the custom label name or index number, to return a single CustomLabel object. The following example creates a new document with an existing custom label layout named "My Labels."

Visual Basic for Applications
  Set ML = Application.MailingLabel
If ML.CustomLabels("My Labels").Valid = True Then
    ML.CreateNewDocument Name:="My Labels"
Else
    MsgBox "The My Labels custom label is not available"
End If

The index number represents the position of the custom mailing label in the CustomLabels collection. The following example displays the name of the first custom mailing label.

Visual Basic for Applications
  If Application.MailingLabel.CustomLabels.Count >= 1 Then
    MsgBox Application.MailingLabel.CustomLabels(1).Name
End If

See Also