View Single Post
 
Old 06-12-2024, 09:41 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 Bold text before first colon only

Hi, I have some code that makes the first words (Defined Terms) at the beginning of paragraphs bold if they are before a tab or a colon. There is an issue if there are additional colons within the same paragraph (see image) or if the colon comes at the end of the paragraph before the tab, it formats those words bold also.

I'm trying to get the code to only bold the words at the beginning of the paragraph before a tab or colon and also if the defined term has quote marks to remove the quotes and bolden the words. I've added before and after documents.

Can anyone advise me on how to get the code to only change the words at the beginning of the paragraphs to bold and nothing else. Thanks

Capture.JPG

Bold Text Before Formatting.docx
Bold Text After Formatting.docx

Code:
Sub BoldBeforeTabsAndColons_Definitions()
'Find text at beginning of paras before tab or colon and format bold without quotes
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
With Selection.Find
  .ClearFormatting
  .Forward = True
  .Wrap = wdFindContinue
  .Format = True
  .MatchWildcards = True
  .Replacement.ClearFormatting
  .text = "([!^13]@^t)" 'bold text before tab beginning of para
  .Replacement.text = "\1"
  .Replacement.Font.Bold = True
  .Execute Replace:=wdReplaceAll
  .text = "^13(\([a-z]{1,}\))"
  .Replacement.text = "^p\1"
  .Replacement.Font.Bold = False
  .Execute Replace:=wdReplaceAll
  .text = "([!^13]@:)" 'bold text before colon beginning of para
  .Replacement.text = "\1"
  .Replacement.Font.Bold = True
  .Execute Replace:=wdReplaceAll
  .text = "^13(\([a-z]{1,}\))"
  .Replacement.text = "^p\1"
  .Replacement.Font.Bold = False
  .Execute Replace:=wdReplaceAll
  End With
  Application.ScreenUpdating = True
End Sub

Last edited by Shelley Lou; 06-13-2024 at 02:47 AM.
Reply With Quote