XL98: Problems Using ColorIndex to Set Color of Borders (183022)
The information in this article applies to:
- Microsoft Excel 98 Macintosh Edition
This article was previously published under Q183022 SYMPTOMS
In Microsoft Excel 98 Macintosh Edition, if you run a Visual Basic for
Applications macro that uses the ColorIndex property to specify a color for
the borders of a cell, some of the borders may fail to use that color or
may not appear. For example, this problem occurs when you use the following
sample code in a macro:
ActiveCell.Borders.ColorIndex = 3
CAUSE
This problem occurs because Microsoft Excel 98 Macintosh Edition applies
the specified color to only the left, right, top, and bottom borders.
WORKAROUNDMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
The following example code uses the ColorIndex property to specify a color
for the borders of a cell or a range of cells.
Left, Right, Top, and Bottom Borders
To use the ColorIndex property for these types of borders, set the
ColorIndex property to the value you want, for example:
ActiveCell.Borders(xlEdgeLeft).ColorIndex = 2
ActiveCell.Borders(xlEdgeRight).ColorIndex = 3
ActiveCell.Borders(xlEdgeTop).ColorIndex = 4
ActiveCell.Borders(xlEdgeBottom).ColorIndex = 5
You can set all four borders to the same value by using a line of code
similar to the following:
ActiveCell.Borders.ColorIndex = 6
Inside Vertical and Inside Horizontal Borders
To use the ColorIndex property for these types of borders, set the
ColorIndex property for the appropriate constant to the correct value, for
example:
Selection.Borders(xlInsideVertical).ColorIndex = 7
Selection.Borders(xlInsideHorizontal).ColorIndex = 8
NOTE: When you use the xlInsideVertical constant, the selected range must
contain at least two columns. When you use the xlInsideHorizontal constant,
the selected range must contain at least two rows. If the selection does
not contain the necessary number of columns or rows, you receive the
following error message:
Run-time error '1004':
Unable to set the ColorIndex property of the Border class
Diagonal Up and Diagonal Down Borders
To use the ColorIndex property for these types of borders, first set the
Weight property of the border, for example:
With Selection.Borders(xlDiagonalUp)
.Weight = xlThin
.ColorIndex = 9
End With
Selection.Borders(xlDiagonalDown).Weight = xlMedium
Selection.Borders(xlDiagonalDown).ColorIndex = 10
NOTE: If you use the ColorIndex property of the diagonal border before you
set its Weight property, the ColorIndex property is ignored, and the border
appears in the default color (black). If you do not set the Weight
property, the border does not appear.
STATUS
This behavior, with the exception of the behavior of diagonal borders, is
by design of Microsoft Excel 98 Macintosh Edition.
Microsoft has confirmed the behavior of diagonal borders to be a problem in
the Microsoft products listed at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 6/17/2005 |
---|
Keywords: | kbbug kbdtacode kbProgramming KB183022 |
---|
|