Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-12-2024, 09:41 AM
Shelley Lou Shelley Lou is offline VBA Bold text before first colon only Windows 10 VBA Bold text before first colon only Office 2016
Expert
VBA Bold text before first colon only
 
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bold Term Macro that DOES NOT bold terms with Quotation Marks NotOriginal Word VBA 2 03-14-2024 02:22 PM
Bold Header if it is not Bold (Check to see if it is Bold) armendarizj Word 2 01-06-2022 05:45 PM
VBA Bold text before first colon only bold (or unbold) section of text instead of bold toggling Burt Word 6 04-06-2019 09:09 AM
VBA Bold text before first colon only Text in #1 is made bold, rest of the document is edited, text in #1 is now not bold footer-assistance Word 1 06-29-2015 03:49 AM
VBA Bold text before first colon only Not Bold text but it comes up bold Pluviophile Word 7 10-22-2013 10:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft