View Single Post
 
Old 07-12-2024, 03:30 AM
Shelley Lou Shelley Lou is offline Windows 10 Office 2016
Expert
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Find Bold Text within Brackets and Add Quotes

I want to change the code below to automatically add bold quotes to the bold text within brackets. At the moment I have to select multiple text to add the quotes. Advice always appreciated.

Before
Before.JPG

After
After.JPG

Code:
Sub BoldTextWithinBrackets_AddQuotes()
'Select multiple bold definitions and apply bold quotes
Application.ScreenUpdating = False
If Selection.Type = wdSelectionIP Then
 'MsgBox Prompt:="You have not selected any text!"
 MsgBox "You have not selected any text!", vbExclamation, "Invalid selection"
 Exit Sub
End If
With Selection.Find
   .ClearFormatting
   .Replacement.ClearFormatting
   .Forward = False
   .Wrap = wdFindStop
   .Format = True
   .MatchWildcards = False
    With Selection.Find
        .text = ""
        .Font.Bold = True
        .Replacement.text = """^&"""
        .Execute Replace:=wdReplaceAll
    End With
    Application.ScreenUpdating = True
   End With
End Sub
Reply With Quote