Share via


Selection Object

Publisher Developer Reference

Represents the current selection in a window or pane. A selection represents either a selected (or highlighted) area in the publication, or it represents the cursor if nothing in the publication is selected. There can only be one Selection object per publication window pane, and only one Selection object in the entire application can be active.

Example

Use the Selection property to return the Selection object. If no object qualifier is used with the Selection property, Microsoft Office Publisher returns the selection from the active pane of the active publication window. The following example copies the current selection from the active publication.

Visual Basic for Applications
  Sub CopySelection()
    Selection.ShapeRange.Copy
End Sub

The following example determines what type of item is selected and, if it is an autoshape, fills the first shape in the selection with color. This example assumes there is at least one item selected in the active pubication.

Visual Basic for Applications
  Sub SelectedShape()
    If Selection.Type = pbSelectionShape Then
        Selection.ShapeRange.Item(1).Fill.ForeColor _
            .RGB = RGB(Red:=200, Green:=20, Blue:=255)
    End If
End Sub

The following example copies the selection and pastes it into the first shape on the second page of the active publication.

Visual Basic for Applications
  Sub CopyPasteSelection()
    Selection.TextRange.Copy
    With ActiveDocument.Pages(2).Shapes(1).TextFrame.TextRange
        .Collapse Direction:=pbCollapseEnd
        .InsertAfter NewText:=vbLf
        .Paste
    End With
End Sub

See Also