By Dan Gookin

When you’re writing in Word 2016, especially if you’re working on an academic paper or even a large fiction work, you might want to spike large chunks of text rather than delete them. To spike text, you select it and then move it down to the end of the document. When you’re “done” writing, review your spikes to see whether anything is worth saving.

Following is code for a spike_text macro that automates the process:

Sub spike_text()

'

' spike_text Macro

' Move selected text to the end of the document

'

If Selection.Type = wdSelectionNormal Then

Selection.Cut

Selection.EndKey Unit:=wdStory

Selection.TypeParagraph

Selection.Paste

Application.GoBack

Application.GoBack

Else

MsgBox "Nothing to spike"

End If

End Sub

This macro contains an if-else structure. The if test determines whether text is selected. If so, the text is cut and pasted at the end of the document. When text isn’t selected, the else part of the equation displays a message box with the text “Nothing to spike.”

This macro was recorded initially and used these keystrokes:

  1. Ctrl+X
  2. Ctrl+End
  3. Ctrl+V
  4. Shift+F5, Shift+F5
    The Shift+F5 keyboard shortcut returns you to the previous editing location in the document.

After recording the keystrokes, the if-else structure was added to ensure that the macro didn’t display an ugly error message when text isn’t selected. This process is part of defensive programming, where you anticipate that not every macro starts under ideal conditions. In this instance, a non-ideal condition is when text isn’t selected.