View Single Post
 
Old 10-14-2024, 05:58 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Shellley, Vivka


While not a perfect check, you could add a simple function to help check for paired quotes:

Code:
Sub PlainDefinition_FormatBold()
'Select one or more definitions with plain text and plain quotes and format bold
Dim rng As Range
  Application.ScreenUpdating = False
  If Selection.Type = wdSelectionIP Then
    MsgBox "You have not selected any text.", vbInformation + vbOKOnly, "Invalid selection"
    Exit Sub
  Else
    Set rng = Selection.Range
    If fcnPaired(rng.Text) Then
      With rng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Forward = False
        .Wrap = wdFindStop
        .Format = True
        .MatchWildcards = True
        .Text = "[""""]*[""""]" 'Find any text within quotes
        .Replacement.Font.Bold = True 'Replacement text is bold
        .Execute Replace:=wdReplaceAll
        .Text = "\([""""]*[""""]\)" 'Find any text within quotes within brackets
        .Replacement.Font.Bold = True
        .Execute Replace:=wdReplaceAll
      End With
      Application.ScreenUpdating = True
    Else
      MsgBox "Quotes in the selected text are not properly paired." & vbCr + vbCr _
           & "Select text containing only properly enclosed quoted text and try again.", vbInformation + vbOKOnly, "OPEN QUOTE"
    End If
    Set rng = Nothing
  End If
lbl_Exit:
  Exit Sub
End Sub

Function fcnPaired(strCheck As String) As Boolean
Dim arrCheck() As String
  fcnPaired = False
  arrCheck = Split(strCheck, Chr(34))
  If UBound(arrCheck) Mod 2 = 0 Then
    fcnPaired = True
  End If
lbl_Exit:
  Exit Function
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote