View Single Post
 
Old 11-16-2016, 07:42 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,344
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

While not wanting to pour scorn on macro suggestion, you'll soon find it's rather inflexible. The following rendition will add parentheses to any selected alpha-numeric string:
Code:
Sub AddParens()
Application.ScreenUpdating = False
Dim i As Long
With Selection.Words.First
  If (InStr(.Text, ")") > 0) Or (InStr(.Text, "(") > 0) Then Exit Sub
  Do While .Characters.Last Like "[ ,.:;?!'" & Chr(7) & "-" & Chr(13) & "]"
    .End = .End - 1
  Loop
  For i = Len(.Text) To 1 Step -1
    With .Characters(i)
      .InsertAfter ")"
      .InsertBefore "("
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
Just don't try it with multi-character roman numerals...

If you assign the macro to a keyboard shortcut, it'll be ready for action without the need to go through the Developer tab, etc.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote