Sub AbbrSwap()
' Paul Beverley - Version 24.11.15
' Swap abbreviation into or out of brackets
addPreEditCodes = False
' Find the start ...
Selection.Expand wdWord
Selection.MoveStart , -1
If Asc(Selection) <> Asc("<") Then Selection.MoveStart , 1
startHere = Selection.Start
' ... and the end of the words (close parenthesis)
Selection.MoveEndUntil cset:=ChrW(8217) & ")", Count:=wdForward
Selection.MoveEnd , 1
allWords = Selection
' find the open parenthesis, to find the two bits of text to swap
parenPos = InStr(allWords, "(")
leftWords = Left(allWords, parenPos - 2)
rightWords = Mid(allWords, parenPos + 1, Len(allWords) - parenPos - 1)
' swap them round and type them back in
If addPreEditCodes = True And InStr(leftWords, ">") = 0 Then
If Len(rightWords) > Len(leftWords) Then
newWords = "" & rightWords & " (" & leftWords + ")"
Else
newWords = "" & leftWords & " (" & rightWords + ")"
End If
Else
newWords = rightWords + " (" + leftWords + ")"
End If
Selection.TypeText Text:=newWords
End Sub