Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Removing color Highlight
Michel Paul 
      
4 years ago
In a database, I have people copying and pasting text from different source in a long text control, set as Rich text.

Sometime, the copied text has a color background.

I need to be able to quickly remove the highlight from the text in the Text control.

Currently, we need to select the text and using the "Text Highlight Color" tool in the "text Formatting" section of the Home tab, select the "No Color" option.

I would like to automate the text color highlight removal using VBA, but I can't find the correct property to use in the VBA command.

I have found a bunch of properties on the web, but they work with Word or Excel. They don't seem to exist in the Access library of properties.

Someone has an idea?

Thanks
Alex Hedley  @Reply  
           
4 years ago
Is there a reason why the rest has to be rich text too?
Dan Jackson  @Reply  
            
4 years ago
I'm with Alex. Does it need to be Rich Text? If you set it as plain text, all formatting will automatically be removed
Michel Paul OP  @Reply  
      
4 years ago
The main reason for the rich text format is that some of the content have link to web sites as part of the text and some information have formatting like numbered list and bullets, bold, italics, etc.

I just want to get rid of the colored background that comes with pasting some text from other sources. This is very distracting.

Thanks
Scott Axton  @Reply  
        
4 years ago
I've done a bit of searching on the Google Machine and it appears like this would be an all or none situation.
You can't "have your cake and eat it too" so to speak.

There are ways to strip all formatting.  Unfortunately you would just have to either put up with the pasted formatting as is OR selectively edit the pasted info to remove the undesired attributes.
Alex Hedley  @Reply  
           
4 years ago
Where's the macro recorder in access when you need it?
Alex Hedley  @Reply  
           
4 years ago
When you select the control and bring up the properties is there not a value there that can be changed?
Michel Paul OP  @Reply  
      
4 years ago
Hi,

I could not find a property about highlight or text back color in the properties.

I really miss the macro recorder in Access

So it looks like either I live with the sometime weird colors or switch to plain text. I will discuss with my team.

Thanks for all you help guys.
Kevin Yip  @Reply  
     
4 years ago
Hi Michel, a rich text field's formatting is done with HTML tags.  A highlighted text in a rich text field would look something like this in HTML, which is embedded in the field in Access:

<font style="background-color:#ffff00">my text</font>

You can see the HTML with a statement such as MsgBox Me!MyRichTextField.

To remove the highlight, you need to remove the <font...> and </font> tags.  It's not a trivial task to remove <font...> because it may have many different attributes you can't predict in advance, like font size, color, etc.  But a tag always ends with ">".  I would use the InStr() function to search for the text "<font" and ">" and delete everything in between.  And of course, it helps to be well-versed in HTML as well.  To remove other types of formatting, you need to be familiar with other tags.
Dan Jackson  @Reply  
            
4 years ago
Good point Kevin!
Alex Hedley  @Reply  
           
4 years ago
Wasn't thinking about that, cheers @Kevin.
Just use MSHTML, parse the HTML into it actual elements then you can check for certain properties, remove them, then resave.
This would make a cool tip/seminar.
Michel Paul OP  @Reply  
      
4 years ago
Thank you for suggestion,

I will look at setting this up, hope fully it will not be beyond my VBA capabilities
Kevin Yip  @Reply  
     
4 years ago
Here is a sample code that will remove highlights in a rich text box.  I tested it and it worked, but be sure to modify it to your needs.  The HTML tag attribute for a highlight is "background-color" within a <font> tag.  My code removes it if it is found inside a <font> tag.  But it won't remove it if "background-color" is legitimate text in your data.  There may be multiple <font> tags, and the code looks for all.  Note that Access may put line breaks within the tags, and my code replaces them with spaces for easier processing. Call this function with, e.g.: Me!MyRichTextField = RemoveHighlights(Me!MyRichTextField)

Private Function RemoveHighlights(s As String) As String
    Dim pos As Integer, pos2 As Integer, pos3 As String
    Dim s2 As String, s3 As String
    
    ' Replace line breaks in the string with spaces.
    s = Replace(s, Chr(13) & Chr(10), " ")
    
    ' Find first instance of the opening tag "<font ".
    pos = InStr(1, s, "<font ")
    
    ' If found, run do loop below.
    Do While pos <> 0
    
        ' Find next instance of ">".
        pos2 = InStr(pos + 6, s, ">")
        
        ' Get text between "<font " and ">".
        s2 = Mid(s, pos + 6, pos2 - pos - 6)
        
        ' Find instance of "background-color" within this string.
        pos3 = InStr(1, s2, "background-color")
        
        ' If found, remove "background-color" from this string
        '   and put modified string back to the original string.
        If pos3 <> 0 Then
            s3 = Replace(s2, "background-color", "")
            s = Replace(s, s2, s3)
        End If
        
        ' Continue to find next instance of "<font "
        pos = InStr(pos + 6, s, "<font ")
    Loop
    
    ' Return resulting string.
    RemoveHighlights = s
End Function
Kevin Robertson  @Reply  
          
4 years ago
Nice
Michel Paul OP  @Reply  
      
4 years ago
Thank you Kevin Yip,

I will give this a try as soon as I come back from vacation
Richard Rost  @Reply  
          
4 years ago
I haven't tested it myself, but it looks solid at a glance. Thanks, Kevin.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/30/2026 4:37:44 AM. PLT: 1s