Selection object (Publisher)

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.

Remarks

Use the Document.Selection property to return the Selection object. If no object qualifier is used with the Selection property, Microsoft Publisher returns the selection from the active pane of the active publication window.

Example

The following example copies the current selection from the active publication.

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 that there is at least one item selected in the active publication.

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.

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

Methods

Properties

See also

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.