I've got a macro written to add parentheses around a sentence in Microsoft Word:
Sub AddParentheses()
Dim iCount As Integer
iCount = 1
While Right(Selection.Text, 1) = " " Or _
Right(Selection.Text, 1) = Chr(13)
Selection.MoveLeft Unit:=wdCharacter, Count:=1, _
Extend:=wdExtend
iCount = iCount + 1
Wend
Selection.InsertAfter ")"
Selection.InsertBefore "("
Selection.MoveRight Unit:=wdCharacter, Count:=iCount
End Sub
It works great when I select only a sentence and run it, but if I accidentally highlight a paragraph break at the end of the sentence, the macro starts slowly highlighting everything in the document, moving from the beginning of my selection to the beginning of the whole document, which invariably crashes the program.
Can anyone point me in the direction of a solution?