I have some code that is supposed to format plain text definitions with quotes, e.g. the "Property" to the
"Property" upon selection. I've set the range to Selection.Range but when selecting the text and running the code, it is formatting all plain text within quotes that have not been selected.
The code needs to be able to handle one selection or multiple selections. I'm not sure where I'm going wrong.
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 Prompt:="You have not selected any text!"
MsgBox "You have not selected any text!", vbExclamation, "Invalid selection"
Exit Sub
End If
Set rng = Selection.Range
With rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = False
.Wrap = wdFindStop
.Format = True
.MatchWildcards = True
.text = "[""""]*[""""]" 'Find plain text within plain quotes
.Replacement.text = "^&" 'Format bold
.Replacement.Font.Bold = True 'Replacement text is bold
.Execute Replace:=wdReplaceAll
.text = "[\(\)]" 'Find plain text with plain quotes within brackets
.Replacement.text = "^&" 'Format bold
.Replacement.Font.Bold = False
.Execute Replace:=wdReplaceAll
Application.ScreenUpdating = True
End With
End Sub