Page Background Problem in Word 2007

S

szcz.andrew

Hello everyone,

I'm trying to change the page color using VBA in Word 2007 and I am
having problems/finding inconsistancies - perhaps someone can help.

I understand that the 'page color' is *supposed* to be visible only
in WebView, but Word does allow you to change the color of the page as
seen in Page Layout, and I would like to do the same thing using VBA.

If you use the ribbon to change the page color, it works fine. If
you record this action, it generates the following code:

ActiveDocument.Background.Fill.ForeColor.ObjectThemeColor = _
wdThemeColorAccent1
ActiveDocument.Background.Fill.ForeColor.TintAndShade = [your
color]
ActiveDocument.Background.Fill.Visible = msoTrue
ActiveDocument.Background.Fill.Solid

This generated macro does not work on a new document (it is
incomplete). In fact, this code will only work if the page color has
been changed using the ribbon at least once. On a brand new document,
it does not change the page color as seen in page layout view.

This means the ribbon page color action performs some additional
work to ensure that page background colors are visible in page layout
view. Anyone have a clue as to what this code may be?

Sincerely,
Andrew
 
T

Tony Jollans

I understand that the 'page color' is *supposed* to be visible only
in WebView, but Word does allow you to change the color of the page as
seen in Page Layout, and I would like to do the same thing using VBA.

In 2007, Page Backgrounds are visible everywhere, not just in Web layout.
This means the ribbon page color action performs some additional
work to ensure that page background colors are visible in page layout
view.

You are absolutely correct. The page background colour *is* set in your
code, and is saved with the document, but it also has to be set to be
visible. Add this to your code:

ActiveDocument.ActiveWindow.View.DisplayBackgrounds = True

--
Enjoy,
Tony

Hello everyone,

I'm trying to change the page color using VBA in Word 2007 and I am
having problems/finding inconsistancies - perhaps someone can help.

I understand that the 'page color' is *supposed* to be visible only
in WebView, but Word does allow you to change the color of the page as
seen in Page Layout, and I would like to do the same thing using VBA.

If you use the ribbon to change the page color, it works fine. If
you record this action, it generates the following code:

ActiveDocument.Background.Fill.ForeColor.ObjectThemeColor = _
wdThemeColorAccent1
ActiveDocument.Background.Fill.ForeColor.TintAndShade = [your
color]
ActiveDocument.Background.Fill.Visible = msoTrue
ActiveDocument.Background.Fill.Solid

This generated macro does not work on a new document (it is
incomplete). In fact, this code will only work if the page color has
been changed using the ribbon at least once. On a brand new document,
it does not change the page color as seen in page layout view.

This means the ribbon page color action performs some additional
work to ensure that page background colors are visible in page layout
view. Anyone have a clue as to what this code may be?

Sincerely,
Andrew
 
S

szcz.andrew

Tony, you're wonderful! That worked perfectly - much appreciated!

Cheers,
Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top