View Single Post
 
Old 01-01-2021, 03:54 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

It is fairly straightforward and works best with ranges which the recorder doesn't use:
Code:
Sub AddEmphasis()
Dim oRng As Range
    Set oRng = Selection.Range
    If Len(oRng) = 0 Then
        MsgBox "Nothing selected", vbCritical
        GoTo lbl_Exit
    End If
    With oRng
        'avoid inadvertently selected spaces at start and end of the selection
        .MoveEndWhile Chr(32), wdBackward
        .MoveStartWhile Chr(32)
        'make selection bold
        .Font.Bold = True
        'add parenthesis and quotation marks
        .InsertBefore Chr(40) & Chr(34)
        .InsertAfter Chr(34) & Chr(41)
        'optional remove bold emphasis from parenthesis and quotation marks
        .Characters.First.Bold = False
        .Characters.First.Next.Bold = False
        .Characters.Last.Bold = False
        .Characters.Last.Previous.Bold = False
    End With
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote