Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2024, 07:42 AM
NotOriginal NotOriginal is offline Bold Term Macro that DOES NOT bold terms with Quotation Marks Windows 11 Bold Term Macro that DOES NOT bold terms with Quotation Marks Office 2021
Novice
Bold Term Macro that DOES NOT bold terms with Quotation Marks
 
Join Date: Mar 2024
Posts: 1
NotOriginal is on a distinguished road
Question Bold Term Macro that DOES NOT bold terms with Quotation Marks

Long time lurker, first time poster. I have a macro for MS Word that searches/bolds 115 terms, however, I need the macro to avoid bolding terms that are in quotations. For example, I have the word closing in bold, but if it is displayed as "closing" then I want that term to be ignored. Is there a way to do this?

A sample of my code is below:

Sub BoldPolicyWords()

Dim wordsToBold(1 To 3) As String
wordsToBold(1) = "word 1"
wordsToBold(2) = "word 2"
wordsToBold(3) = "word 3"


For i = 1 To 3

With Selection.Find
.Text = wordsToBold(i)
.Replacement.Text = "" ' Replace with empty string (optional)
.Replacement.Font.Bold = True
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
End With



Selection.Find.Execute Replace:=wdReplaceAll
Next i

End Sub
Reply With Quote
  #2  
Old 03-14-2024, 09:48 AM
vivka vivka is offline Bold Term Macro that DOES NOT bold terms with Quotation Marks Windows 7 64bit Bold Term Macro that DOES NOT bold terms with Quotation Marks Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi, former lurker, current poster ! If the words to bold are flanked by spaces, I think, the solution is quite simple:
Code:
wordsToBold(1) = " word 1 "
wordsToBold(2) = " word 2 "
wordsToBold(3) = " word 3 "
or:

Code:
wordsToBold(1) = "word 1 "
wordsToBold(2) = "word 2 "
wordsToBold(3) = "word 3 "
If the codes above meet your needs, I will not propose a more complicated solution.
Reply With Quote
  #3  
Old 03-14-2024, 02:22 PM
gmaxey gmaxey is offline Bold Term Macro that DOES NOT bold terms with Quotation Marks Windows 10 Bold Term Macro that DOES NOT bold terms with Quotation Marks Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Sometimes I find it easier to just bold all the undo the spec cases.


Since there is good chance some of the words may start a sentence or end a sentence the space suggestions Vivka makes may not work.


Code:
Sub BoldPolicyWords()
Dim wordsToBold() As String
Dim lngIndex As Long
Dim oRng As Range
wordsToBold = Split("Word1,Word2,Word3", ",")
  For lngIndex = 0 To UBound(wordsToBold)
    Set oRng = ActiveDocument.Range
    With oRng.Find
     .Text = wordsToBold(lngIndex)
     .Replacement.Font.Bold = True
     .Forward = True
     .Wrap = wdFindStop
     .MatchWholeWord = True
     .Execute Replace:=wdReplaceAll
    End With
    Set oRng = ActiveDocument.Range
    With oRng.Find
     .Text = "[^0147^34]" & wordsToBold(lngIndex) & "[^0148^34]"
     .Replacement.Font.Bold = False
     .Forward = True
     .Wrap = wdFindStop
     .MatchWildcards = True
     .MatchWholeWord = True
     Do While .Execute
       With oRng
        .MoveEnd Unit:=wdCharacter, Count:=-1
        .MoveStart Unit:=wdCharacter, Count:=1
        .Font.Bold = False
        .Collapse wdCollapseEnd
       End With
     Loop
    End With
  Next lngIndex
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
ignore quotations



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bold Term Macro that DOES NOT bold terms with Quotation Marks Searching a Word document with multiple words from a list (over 1,000 terms) and BOLD all occurrence Nicknamednick Word 9 09-28-2022 05:41 PM
Bold Header if it is not Bold (Check to see if it is Bold) armendarizj Word 2 01-06-2022 05:45 PM
Bold Term Macro that DOES NOT bold terms with Quotation Marks bold (or unbold) section of text instead of bold toggling Burt Word 6 04-06-2019 09:09 AM
Customised heading styles to bold but they're not coming out bold seanspotatobusiness Word 2 06-02-2017 02:26 PM
Format Bold in one line makes all lines bold Nitte Word 2 02-07-2013 12:34 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:23 AM.


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