Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-01-2021, 03:54 AM
gmayor's Avatar
gmayor gmayor is offline Macro Help - Wrap a term with characters and formatting Windows 10 Macro Help - Wrap a term with characters and formatting Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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
 



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
Macro Help - Wrap a term with characters and formatting Subtract value if cell contains X term Jue92 Excel 4 11-01-2016 01:45 AM
Macro Help - Wrap a term with characters and formatting Macro to insert multiple pictures to word to a specific size and text wrap mescaL Word VBA 3 11-03-2014 10:51 PM
Macro Help - Wrap a term with characters and formatting Insert input box into macro to allow user to define search term Hoxton118 Word VBA 3 05-19-2014 02:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:12 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft