Satanas
Satanas

Reputation: 171

How change the background color in a Word doc?

I wanted to know how can I change the background color of the text in Word on all my doc. For exemple I got some text with blue/red/pink background color and I want that the bg color of all my doc white.

I got and exemple for the font color :

Sub color()
'
' color Macro
'
'

Dim Plage As Object, Wrd As Object
 
Set Plage = ActiveDocument.Content.Words
 
For Each Wrd In Plage
    If Wrd.Font.color = RGB(0, 0, 255) Then _
    Wrd.Font.color = RGB(128, 128, 128)
Next Wrd
 

End Sub

But I don't know how to apply this VBA code for the background color. Maybe with Document.Background property ?

Upvotes: 0

Views: 2436

Answers (1)

FunThomas
FunThomas

Reputation: 29592

There are three background color settings you have to deal with:

  • You can have text marked with a Text Highlight. This can be modified with Range.HighlightColorIndex. To remove the highlight, use wdNoHighlight
  • You can have Shading. Shading is set on paragraph level can can be modified with Range.Shading.BackgroundPatternColor. To remove it, use wdColorAutomatic
  • You can have set the background color of a whole document. This can be modified using Background.Fill of the document. Either set the ForeColor to white, or set the visible-property to false.

To clean everything at once, use something like this:

Sub RemoveBackgroundColor()
    With ActiveDocument.Content
        .HighlightColorIndex = wdNoHighlight
        .Shading.BackgroundPatternColor = wdColorAutomatic
    End With
    ActiveDocument.Background.Fill.Visible = msoFalse
End Sub

Upvotes: 6

Related Questions