![]() |
|
#1
|
|||
|
|||
|
Hi
I'm trying to write a macro to find and replace all text that's RGB 0 0 225 to RGB 0 0 0. I'm find with code for the body of the word document, but can't seem to figure out how to change the colour in the Headers/Footers! Is it possible?
|
|
#2
|
||||
|
||||
|
If your document has only one Section, you can use code like:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim RngStory As Range
For Each RngStory In ActiveDocument.StoryRanges
With RngStory.Find
.ClearFormatting
.Text = ""
.Font.ColorIndex = wdBlue
With .Replacement
.ClearFormatting
.Text = ""
.Font.ColorIndex = wdBlack
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Execute Replace:=wdReplaceAll
End With
Next RngStory
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
it didn't work in the headers/footers.There are several different sections, headers/footers don't start on the first page/Section, starts in Sec 3. Most have the "Same as previous" set up though... Thoughts? I had tried various combinations of this code, but it only changed the colour in the body, not the Headers/Footers. Code:
Sub BluetoBlack() ' ' BluetoBlack Macro ' ' Selection.Find.ClearFormatting Selection.Find.Font.Color = wdColorBlue Selection.Find.Replacement.ClearFormatting Selection.Find.Replacement.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.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(1).Range.Font.Color = wdColorAutomatic End Sub Last edited by trillium; 10-20-2015 at 08:27 PM. Reason: add file |
|
#4
|
||||
|
||||
|
As I said, the code was sufficient for a document with one Section. To work with multiple Sections, you'd need code like:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range, Sctn As Section, HdFt As HeaderFooter
With ActiveDocument
For Each Rng In .StoryRanges
Call FndRepRng(Rng)
Next
For Each Sctn In .Sections
For Each HdFt In Sctn.Headers
With HdFt
If .LinkToPrevious = False Then
Call FndRepRng(HdFt.Range)
End If
End With
Next
For Each HdFt In Sctn.Footers
With HdFt
If .LinkToPrevious = False Then
Call FndRepRng(HdFt.Range)
End If
End With
Next
Next
End With
End Sub
Sub FndRepRng(Rng As Range)
With Rng.Find
.ClearFormatting
.Text = ""
.Font.ColorIndex = wdBlue
With .Replacement
.ClearFormatting
.Text = ""
.Font.ColorIndex = wdBlack
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Execute Replace:=wdReplaceAll
End With
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#5
|
|||
|
|||
![]() ![]() Thank you SO MUCH!!! This works like a charm!! |
|
| Tags |
| colour, font, header and footer |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Find & Replace in Header/Footer in 1000 files
|
amodiammmuneerk@glenmarkp | Word | 12 | 03-05-2018 03:31 AM |
Created VBA to Find and Replace in Body, Header and Footer with Highlighting the replacement text
|
QA_Compliance_Advisor | Word VBA | 11 | 09-23-2014 04:40 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 in Header/Footer
|
PReinie | Word | 6 | 01-22-2014 06:45 PM |
| Change font of STYLEREF in Header/Footer | SQLUSA | Word | 4 | 08-13-2012 01:54 PM |