Borders in character and paragraph styles
So what's the problem with borders and styles?
For basic issues in of controlling borders in styles, see Border basics. The issues for character and paragraph styles are:
- For character and paragraph styles, a
.Borders
property can have 1 or 5 borders. - Sometimes you can set the distance between the borders and the text, and sometimes you can't.
- Sometimes can you set a shadow on the borders, and sometimes you can't.
Microsoft hasn't documented how the borders are supposed to behave. This page merely describes my experience.
Character styles
Character style: Borders on the style itself
- In the object model:
Style.Borders
- Doesn't work. Accessing
Style.Borders
for a character style causes error 5900 'This property is not allowed for character styles'.
Character style: Borders on the font of the character style
- In the object model:
Style.Font.Borders
- Number of borders: 1. You can't specify different borders for top, left, bottom or right.
In thewdBorderType
enumeration, there is no constant for "the one and only border of a Font object". We have to usemyStyle.Font.Borders(1)
ormyStyle.Font.Borders(wdBorderTop)
. Any other value will cause an error. - Distances from text? No.
.Shadow
? Yes. Must set the.Shadow
to True only after you set the.Borders(1).LineStyle
and only if the.LineStyle
is notwdLineStyleNone
.Enable
is inconsistent. You can read the property reliably, but you cannot set a border using.Enable = True
.- You can use
.Visible
to delete a border. For example
ActiveDocument.Styles("MyCharacterStyle").Font.Borders(wdBorderTop).Visible = False.
- As with borders in general, you can't use
.Visible
to set a border reliably.
Paragraph styles
Paragraph style: Borders on the paragraph
- In the object model:
Style.Borders
orStyle.ParagraphFormat.Borders
- Number of borders: 5. You can specify different borders for top, left, bottom and right, plus horizontal. Horizontal borders appear between paragraphs.
Style.Borders
andStyle.ParagraphFormat.Borders
appear to be the same object. If you change one, Word automatically changes the other.I've seen at least one case where
Style.Borders
causes problems, for example if you set the top or bottom border, Word also sets the.Borders(wdBorderRight)
. Or, in an otherwise borderless style, if you setStyle.Borders.Shadow = True
, Word adds a right border, but no other. I haven't experienced the same problems usingStyle.ParagraphFormat.Borders
. So I use that. - Distances between text? Yes
- Shadow? Yes, but you see it only on the bottom border. It doesn't cause an error to set it for other borders, but you don't see it.
Paragraph style: Borders on the text of the paragraph
- In the object model:
Style.Font.Borders
- Number of borders: 1. You can't specify different borders for top, left, bottom or right. Use
myStyle.Borders(1)
- Distances from text? No.
- Shadow? Yes. Must set the
.Shadow
to True only after you set the.Borders(1).LineStyle
and only if the.LineStyle
is notwdLineStyleNone
Paragraph style: Borders on the bullet or numbering shown on a paragraph
- In the object model:
Style.ListTemplate.ListLevels(n).Font.Borders
- Number of borders: 1. You can't specify different borders for top, left, bottom or right. In the wdBorderType enumeration, there is no constant for "the one and only border of a Font object". Use
myStyle.ListTemplate.ListLevels(n).Font.Borders(1)
ormyStyle.ListTemplate.ListLevels(n).Font.Borders(wdBorderTop)
. Any other value will cause an error. - Notes
- The border is generally visible only after you do a screen refresh, eg by displaying print preview.
- The border encloses both the number (including any preceding text, such as "Chapter ") and the trailing character (eg a tab).
- Distances from text? Not available.
- Shadow? Yes. Must set the
.Shadow
to True only after you set the.LineStyle
and only if the.LineStyle
is notwdLineStyleNone