View Single Post
 
Old 09-25-2024, 08:13 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

A while ago, Greg very kindly updated some code for me to add quotes to bold text within brackets (see link below). At the time, the documents I was working on had an opening bracket bold text closing bracket. I'm now working on documents where there is also plain text with bold text within the brackets e.g. (the Tenant) or (the Property).

What can I add to the code to ignore the plain text and just add double bold quotes to the bold text?

https://www.msofficeforums.com/word-...ckets-add.html

Code:
Sub DPU_BoldTextWithinBrackets_AddQuotes()
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  Application.ScreenUpdating = False
  With oRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Wrap = wdFindStop
    .Format = True
    .MatchWildcards = False
    .Font.Bold = True
    While .Execute
      On Error GoTo Err_Handler
      If oRng.Characters.First.Previous = Chr(40) And oRng.Characters.Last.Next = Chr(41) Then
        oRng.InsertBefore Chr(34)
        oRng.Characters.First.Font.Bold = True
        oRng.InsertAfter Chr(34)
      End If
Err_Handler:
      oRng.Collapse wdCollapseEnd
    Wend
  End With
  Application.ScreenUpdating = True
lbl_Exit:
  Exit Sub
End Sub
Reply With Quote