![]() |
|
#1
|
|||
|
|||
![]()
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 |
#2
|
||||
|
||||
![]()
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 |
#3
|
||||
|
||||
![]()
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] |
#4
|
|||
|
|||
![]()
Graham, Paul, as always - thank you
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
bertietheblue | Word | 2 | 04-15-2016 12:30 PM |
![]() |
trillium | Word VBA | 4 | 10-20-2015 10:39 PM |
![]() |
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 |
![]() |
BlueClearSky | Word | 6 | 11-22-2013 03:34 PM |