Emacs's control-K in Microsoft Word

This VBA (Visual Basic for Applications) macro simulates the "Control-K" command of Emacs (delete to the end of line).

Sub EmacsControlK() 
' EmacsControlK Macro 
Dim oRng As Word.Range 
If Selection.Information(wdWithInTable) Then 
        Set oRng = Selection.Cells(1).Range 
        oRng.MoveEnd wdCharacter, -1 
        oRng.Start = Selection.Start 
        Selection.EndKey Unit:=wdLine, Extend:=wdExtend 
        If Selection.End > Selection.Start + 1 Then 
                Selection.End = Selection.End - 1 
        End If 
End If 
End Sub 

Copyright © Ben Bullock 2009-2017. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com). / Privacy / Disclaimer