![]() |
|
#2
|
||||
|
||||
|
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 |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Formatting ID numbers to insert dashes in between some characters | shaun0406 | Word VBA | 6 | 12-22-2020 09:36 AM |
| Macro to wrap each section in a document with some text | mattbrad | Word VBA | 3 | 07-22-2019 03:13 AM |
Subtract value if cell contains X term
|
Jue92 | Excel | 4 | 11-01-2016 01:45 AM |
Macro to insert multiple pictures to word to a specific size and text wrap
|
mescaL | Word VBA | 3 | 11-03-2014 10:51 PM |
Insert input box into macro to allow user to define search term
|
Hoxton118 | Word VBA | 3 | 05-19-2014 02:03 AM |