Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-04-2020, 12:15 PM
alex100 alex100 is offline Find and change the background color of certain keywords Windows 7 64bit Find and change the background color of certain keywords Office 2016
Advanced Beginner
Find and change the background color of certain keywords
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default Find and change the background color of certain keywords

I'm using the code below to search for highlighted keywords and change their look...

Code:
With ActiveDocument.Content.Find
    .ClearFormatting
    .Font.Shading.BackgroundPatternColor = RGB(235, 214, 214)
    With .Replacement
        .ClearFormatting
        .Font.Bold = True
        .Font.ColorIndex = wdWhite
    End With
    .Execute FindText:="", ReplaceWith:="", _
    Format:=True, Replace:=wdReplaceAll
  End With
Beside making them bold and changing their font color, I'd also like to change their background color. I tried all sorts of ways using the
two codes below, but nothing seemed to work...

Code:
.Font.Shading.BackgroundPatternColor = RGB(0, 0, 0)
.Font.HighlightColorIndex = wdBlack
So, in the end they should be bold, with a white font color and black background.



Changing them this way make them more easily noticeable when printing the document in black and white. That's what I'm using the code for.

Can anyone help me, please?

Thank you,
Alex
Reply With Quote
  #2  
Old 05-04-2020, 03:30 PM
macropod's Avatar
macropod macropod is offline Find and change the background color of certain keywords Windows 7 64bit Find and change the background color of certain keywords Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

There is no such property as:
.Font.HighlightColorIndex = wdBlack
Moreover, you can't set the HighlightColorIndex that way via Find/Replace. You need to use something like:
Code:
Options.DefaultHighlightColorIndex = wdBlack
With ActiveDocument.Content.Find
  .ClearFormatting
  .Font.Shading.BackgroundPatternColor = RGB(235, 214, 214)
  With .Replacement
    .ClearFormatting
    .Font.Bold = True
    .Font.ColorIndex = wdWhite
    .Font.Shading.BackgroundPatternColor = RGB(0, 0, 0)
    .Highlight = True
  End With
  .Execute FindText:="", ReplaceWith:="", Format:=True, Replace:=wdReplaceAll
End With
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-04-2020, 11:19 PM
alex100 alex100 is offline Find and change the background color of certain keywords Windows 7 64bit Find and change the background color of certain keywords Office 2016
Advanced Beginner
Find and change the background color of certain keywords
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default

Wonderful! Thank you very much, Paul!

Alex
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Background color change with drop down list Wolfin2010 Excel 1 02-02-2020 11:59 AM
how to change the selected area background color wordyg Word 0 01-28-2019 09:10 PM
Find and change the background color of certain keywords VBA change font color to background color donaldadams1951 Word VBA 6 05-31-2018 04:36 PM
Change excel background color, strange... sojiro Excel 7 04-18-2018 10:07 AM
Can't change table background color in the header in Microsoft Word 2011 simeon1 Word 0 10-13-2014 11:07 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:13 PM.


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