Microsoft Word Cut Paste Method using VBA (Visual Basic for Applications)

Microsoft Word Cut Paste Method using VBA (Visual Basic for Applications)

Cut

Method removes the selected object or text or content and move into the clipboard. In this article we will cut a line of text and paste at the end of document. Follow the screenshot where we made a selection to the line and same will be moved at the end of document using VBA code.

Code example

Sub CutPasteExample()
    'bind selection
    Dim oSelection As Selection
    Set oSelection = Selection
    
    'Check selection type
    If oSelection.Type = wdSelectionNormal Then
        'Perform cut into Clipboard
        Selection.Cut
        
        'Move pointer at the end of document
        oSelection.EndKey Unit:=wdStory
        
        'Perofrm paste
        oSelection.Paste
    End If
    
    'Memory cleanup
    Set oSelection = Nothing
End Sub

Output

Observe the difference. Please leave your comments or queries under comment section. Next >> Highlight Text or Selection in Document VBA

Leave a Reply

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