Microsoft Word Collapse Method VBA (Visual Basic for Applications)

Microsoft Word Collapse Method VBA (Visual Basic for Applications)

Collapse

Method collapses a selection or cursor to the starting or ending position in a range based on direction. After a selection is collapsed, the starting and ending points turns equal.

Syntax

expression.Collapse(_Direction_)

Direction

Its an optional argument which is variant in nature, following constants can be passed to move cursor in a direction which are the members of WdCollapseDirection  enum:

  1. wdCollapseStart : collapse cursor to start of selection. This is default
  2. wdCollapseEnd : collapse cursor to the end of selection

Example

Public Sub CollapseExample()
    'Grabe Selection
    Dim oRange As Range
    Set oRange = Selection.Range
    
    'Collapse Start
    oRange.Collapse Direction:=wdCollapseStart
    
    'Collapse end
    oRange.Collapse Direction:=wdCollapseEnd
    
    'Memory cleanup
    Set oRange = Nothing
End Sub

Please leave your comments or queries under comment section also please do subscribe to out blogs to keep your self upto date.

Leave a Reply

Your email address will not be published. Required fields are marked *