Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-20-2015, 08:48 AM
trillium trillium is offline Find/replace font colour in all header/footer Windows 7 32bit Find/replace font colour in all header/footer Office 2007
Novice
Find/replace font colour in all header/footer
 
Join Date: Oct 2015
Posts: 4
trillium is on a distinguished road
Question Find/replace font colour in all header/footer

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?

Reply With Quote
  #2  
Old 10-20-2015, 02:34 PM
macropod's Avatar
macropod macropod is online now Find/replace font colour in all header/footer Windows 7 64bit Find/replace font colour in all header/footer Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 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]
Reply With Quote
  #3  
Old 10-20-2015, 08:26 PM
trillium trillium is offline Find/replace font colour in all header/footer Windows 7 32bit Find/replace font colour in all header/footer Office 2007
Novice
Find/replace font colour in all header/footer
 
Join Date: Oct 2015
Posts: 4
trillium is on a distinguished road
Default

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
I've attached a sample mock-up to this thread.
Attached Files
File Type: doc find replace colour example.doc (119.0 KB, 10 views)

Last edited by trillium; 10-20-2015 at 08:27 PM. Reason: add file
Reply With Quote
  #4  
Old 10-20-2015, 08:53 PM
macropod's Avatar
macropod macropod is online now Find/replace font colour in all header/footer Windows 7 64bit Find/replace font colour in all header/footer Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

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]
Reply With Quote
  #5  
Old 10-20-2015, 10:39 PM
trillium trillium is offline Find/replace font colour in all header/footer Windows 7 32bit Find/replace font colour in all header/footer Office 2007
Novice
Find/replace font colour in all header/footer
 
Join Date: Oct 2015
Posts: 4
trillium is on a distinguished road
Thumbs up Solved




Thank you SO MUCH!!! This works like a charm!!
Reply With Quote
Reply

Tags
colour, font, header and footer

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/replace font colour in all header/footer Find & Replace in Header/Footer in 1000 files amodiammmuneerk@glenmarkp Word 12 03-05-2018 03:31 AM
Find/replace font colour in all header/footer 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 font colour in all header/footer 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

Other Forums: Access Forums

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