Ruslan  Allabergenov
Ruslan Allabergenov

Reputation: 97

MS Word change background color with macro

Can I change the background color of the page in Microsoft Word 2003 (2007, 2010, 2013) through a macro?

I am attempting to create a Word macro (Microsoft Word 2013) to change the page background color. I began by recording the keystrokes - this is the recorded macro:

Sub WritingLayout() 
    ActiveDocument.Background.Fill.ForeColor.RGB = RGB(255, 255, 204)    
    ActiveDocument.Background.Fill.Transparency = 0#     
    ActiveDocument.Background.Fill.PresetTextured msoTextureParchment     
End Sub 

This macro does not work on new documents.

Upvotes: 1

Views: 7168

Answers (1)

Ruslan  Allabergenov
Ruslan Allabergenov

Reputation: 97

I found how to do it. Just add this line before the vba code:

ActiveDocument.ActiveWindow.View.DisplayBackgrounds = True

Here is the entire macro:

Sub WritingLayout()
'
' WritingLayout Macro
'
    ActiveDocument.ActiveWindow.View.DisplayBackgrounds = True
    ActiveDocument.Background.Fill.ForeColor.RGB = RGB(255, 255, 204)
    ActiveDocument.Background.Fill.Transparency = 0#
    ActiveDocument.Background.Fill.PresetTextured msoTextureParchment
End Sub

Upvotes: 5

Related Questions