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 the wdBorderType enumeration, there is no constant for "the one and only border of a Font object". We have to use myStyle.Font.Borders(1) or myStyle.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 not wdLineStyleNone
  • .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 or Style.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 and Style.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 set Style.Borders.Shadow = True, Word adds a right border, but no other. I haven't experienced the same problems using Style.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 not wdLineStyleNone

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) or myStyle.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 not wdLineStyleNone

 

Related pages