Label Property

Microsoft Publisher Visual Basic

Label Property

Returns or sets a Label object that represents a single unique label design available on the system. Read/write.

expression.Label

expression    Required. An expression that returns a PageSetup object.

Remarks

The returned Label object is contained within the AvailableLabels collection, which is accessed by using the AvailableLabels property.

Only labels that are relevant in the current language/locale are available programmatically.

Example

The following example demonstrates using the Label property to return the fifth label available on the system and modify its properties to create a custom label. Various label properties are set for this label, and then a text box and some text are added to the label. All pages that contain this custom label will have the properties that are set in this example.

Dim theLabel As Label

With ActiveDocument.PageSetup
    .Label = .AvailableLabels(5)  ' Label 5 is Avery 5164
    Set theLabel = .Label
    With theLabel
        .LeftMargin = InchesToPoints(0.15)
        .TopMargin = InchesToPoints(0.15)
        .HorizontalGap = InchesToPoints(0.1)
        .VerticalGap = InchesToPoints(0.1)
    End With
End With

With ActiveDocument.Pages(4).Shapes.AddShape(msoShapeRectangle, _
        5, 5, (theLabel.Width - 10), (theLabel.Height - 10))
    With .TextFrame.TextRange
        .Font.Name = "Verdana"
        .Font.Size = 12
        .Text = "Here is some label text."
    End With
End With
		

The following example demonstrates that certain properties of the Label object are read-only if accessed without using .PageSetup.Label.

Dim theLabel As Label

Set theLabel = ActiveDocument.PageSetup.AvailableLabels(5)

With theLabel
    ' Trying to set any of the following four properties will return an error.
    ' All of these properties are read-only if accessed without using
    ' .PageSetup.Label.
    .LeftMargin = InchesToPoints(0.15)
    .TopMargin = InchesToPoints(0.15)
    .HorizontalGap = InchesToPoints(0.1)
    .VerticalGap = InchesToPoints(0.1)
End With