Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-18-2025, 08:40 PM
leaning leaning is offline Highlight a line of text if it only contains black characters. Windows 7 64bit Highlight a line of text if it only contains black characters. Office 2010 64bit
Novice
Highlight a line of text if it only contains black characters.
 
Join Date: Jan 2011
Posts: 19
leaning is on a distinguished road
Default Highlight a line of text if it only contains black characters.

Hello! I have bulleted text that I run many macros on and they change the words different colors depending on what they find.

What I am trying to do now with a macro is what I am doing manually: look for every line that is just wdAutomatic black. No other colors. If it's just black, that line of text requires more work so that one of the other macros will catch it.

Here is the code I started, but it's missing the "loop through all the lines on the page" part.

<code>
Sub JustBlack()
'
' JustBlack Macro: If the line only has black text and no other colors, then highlight that line yellow.
'
Selection.Find.Execute
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorAutomatic


With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Range.HighlightColorIndex = wdYellow
End Sub
</code>

I appreciate your help!!
Reply With Quote
  #2  
Old 04-19-2025, 12:09 AM
gmayor's Avatar
gmayor gmayor is offline Highlight a line of text if it only contains black characters. Windows 10 Highlight a line of text if it only contains black characters. Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

There are no 'lines' in a Word document. The following will highlight text formatted as wdColorAutomatic
Code:
    With Selection.Find
        .ClearFormatting
        .Font.Color = wdColorAutomatic
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        Do While .Execute
            Selection.Range.HighlightColorIndex = wdYellow
        Loop
    End With
If by line you mean paragraph then use the following instead to highlight paragraphs that are all formatted as wdAuto
Code:
Dim oRng As Range
Dim oPara As Paragraph
    For Each oPara In ActiveDocument.Paragraphs
        If oPara.Range.Font.ColorIndex = wdAuto Then
            oPara.Range.HighlightColorIndex = wdYellow
        End If
    Next oPara
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 04-19-2025, 12:27 AM
macropod's Avatar
macropod macropod is offline Highlight a line of text if it only contains black characters. Windows 10 Highlight a line of text if it only contains black characters. Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

If you're working with lines within a paragraph and no manual line-breaks, the code in:
https://www.msofficeforums.com/word-...-document.html
shows how you can process a document line-by-line.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 04-19-2025, 08:41 AM
leaning leaning is offline Highlight a line of text if it only contains black characters. Windows 7 64bit Highlight a line of text if it only contains black characters. Office 2010 64bit
Novice
Highlight a line of text if it only contains black characters.
 
Join Date: Jan 2011
Posts: 19
leaning is on a distinguished road
Thumbs up Thank you!!

Quote:
Originally Posted by gmayor View Post
There are no 'lines' in a Word document. If by line you mean paragraph then use the following instead to highlight paragraphs that are all formatted as wdAuto
Code:
Dim oRng As Range
Dim oPara As Paragraph
    For Each oPara In ActiveDocument.Paragraphs
        If oPara.Range.Font.ColorIndex = wdAuto Then
            oPara.Range.HighlightColorIndex = wdYellow
        End If
    Next oPara
You got it!! Thanks for your help!!
Attached Images
File Type: png Screenshot 2025-04-19 114226.png (56.5 KB, 13 views)
Reply With Quote
  #5  
Old 04-20-2025, 05:09 AM
gmaxey gmaxey is offline Highlight a line of text if it only contains black characters. Windows 10 Highlight a line of text if it only contains black characters. Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Graham has provide a solution that works for you. However, to your stated requirement "bulleted" text, the following minor modification will limit processing only to those type paragraphs:

Code:
Sub ScratchMacro()
'A basic Word Macro modified by Gregory K. Maxey
Dim oRng As Range
Dim oPara As Paragraph
    For Each oPara In ActiveDocument.Paragraphs
      If oPara.Range.ListFormat.ListType = wdListBullet Then
        If oPara.Range.Font.ColorIndex = wdAuto Then
            oPara.Range.HighlightColorIndex = wdYellow
        End If
      End If
    Next oPara
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 04-20-2025, 12:02 PM
leaning leaning is offline Highlight a line of text if it only contains black characters. Windows 7 64bit Highlight a line of text if it only contains black characters. Office 2010 64bit
Novice
Highlight a line of text if it only contains black characters.
 
Join Date: Jan 2011
Posts: 19
leaning is on a distinguished road
Thumbs up Thanks!

Thanks, Greg! I appreciate your help!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Highlight a line of text if it only contains black characters. Help to Highlight a cell that has less than 5 characters Cendrinne Word VBA 12 11-08-2020 11:05 PM
Highlight a line of text if it only contains black characters. Extract Line of Text w/ specific characters up to the paragraph character, send to Excel dmarie123 Word VBA 10 07-20-2015 12:16 AM
Highlight a line of text if it only contains black characters. Highlight only the characters ER when it occurs in SEVERE. norgro Word VBA 3 02-18-2013 05:14 PM
How to import a text file but skip the first line regardless of characters? omahadivision Excel Programming 7 02-01-2013 08:30 PM
Highlight a line of text if it only contains black characters. Highlight the first X number of characters 14spar15 Word 1 11-13-2011 11:17 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:53 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