Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-05-2021, 11:51 PM
LQuinn LQuinn is offline find/replace all text not a specific colour? Windows 10 find/replace all text not a specific colour? Office 2019
Novice
find/replace all text not a specific colour?
 
Join Date: Jan 2021
Location: Western Australia
Posts: 20
LQuinn is on a distinguished road
Default find/replace all text not a specific colour?

hi all, wondering if it's possible to use find/replace to manage font colours?



i'm wanting to find all text that isn't a specific RGB, and then depending on where it is in the document, set it to the standard RGB

this is what i have so far which does work, i'm just wondering if this is possible with find/replace in a range, or if there is a better way?

thanks!

Code:
Private Sub Get_Non_Grey_Font_Colour()
'
' affects ALL document content - ignores tables and charts
'
' find text not in 80% grey
'
    Dim objPara As Paragraph
    Dim lng80PercentGrey As Long
    Dim rngTemp As Range
    lng80PercentGrey = RGB(80, 84, 77)
    
    For Each objPara In ActiveDocument.Paragraphs
        If objPara.Range.Font.TextColor <> lng80PercentGrey Then
            objPara.Range.Select
            If Selection.Information(wdWithInTable) Then
                Set rngTemp = Selection.tables(1).Range
                rngTemp.Collapse wdCollapseEnd
                rngTemp.Select
            Else
                objPara.Range.Select
                objPara.Range.Font.TextColor = lng80PercentGrey
            End If
        End If
    Next objPara
    
    Set objPara = Nothing
    Set rngTemp = Nothing

    Debug.Print Now & " - " & "finished!"
End Sub
Reply With Quote
  #2  
Old 04-06-2021, 02:29 AM
gmayor's Avatar
gmayor gmayor is offline find/replace all text not a specific colour? Windows 10 find/replace all text not a specific colour? Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,104
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 of
Default

Why not simply apply the colour to all text that is not in a table? e.g.


Code:
Sub Macro1()
Dim oStory As Range
Dim oPara As Paragraph
    For Each oStory In ActiveDocument.StoryRanges
        For Each oPara In oStory.Paragraphs
            If Not oPara.Range.Information(wdWithInTable) Then
                oPara.Range.Font.Color = RGB(80, 84, 77)
            End If
        Next oPara
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                For Each oPara In oStory.Paragraphs
                    If Not oPara.Range.Information(wdWithInTable) Then
                        oPara.Range.Font.Color = RGB(80, 84, 77)
                    End If
                Next oPara
            Wend
        End If
    Next oStory
lbl_Exit:
    Set oStory = Nothing
    Exit Sub
End Sub
__________________
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-06-2021, 03:42 AM
macropod's Avatar
macropod macropod is offline find/replace all text not a specific colour? Windows 10 find/replace all text not a specific colour? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Tbl As Table, Rng As Range, Gray80 As Long
Gray80 = RGB(80, 84, 77)
With ActiveDocument
  Set Rng = .Range(0, 0)
  For Each Tbl In Tables
    With Rng
      .End = Tbl.Range.Start
      .Font.Color = Gray80
      .Start = Tbl.Range.End
    End With
  Next
  Rng.End = .Range.End
  Rng.Font.Color = Gray80
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 04-06-2021, 04:51 PM
LQuinn LQuinn is offline find/replace all text not a specific colour? Windows 10 find/replace all text not a specific colour? Office 2019
Novice
find/replace all text not a specific colour?
 
Join Date: Jan 2021
Location: Western Australia
Posts: 20
LQuinn is on a distinguished road
Default

Graham, Paul, as always - thank you
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
find/replace all text not a specific colour? How do I select all text highlighted in a specific colour? bertietheblue Word 2 04-15-2016 12:30 PM
find/replace all text not a specific colour? Find/replace font colour in all header/footer trillium Word VBA 4 10-20-2015 10:39 PM
find/replace all text not a specific colour? VBA Table – Search All Tables - Find & Replace Text in Table Cell With Specific Background Color jc491 Word VBA 8 09-30-2015 06:10 AM
Word VBA Find Table Text Shading Colour and replace with another QA_Compliance_Advisor Word VBA 10 09-19-2014 08:36 AM
find/replace all text not a specific colour? Quickest way to change text to Arial size 11 specific colour BlueClearSky Word 6 11-22-2013 03:34 PM

Other Forums: Access Forums

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