XLS Object
 
Syntax
 
XLS.SetColor Row1, Col1[, InteriorColor][, FontColor][, BorderColor][, Row2][, Col2]
 
Description
Sets the background color, font color and/or border color of one or more cells in the active worksheet.
 
Colors are specified as standard Long integer RGB values (e.g. vbRed, vbBlue, RGB(255,128,0)). Pass -1 for any color parameter that should not be changed.
 
When Row2 and Col2 are specified, a rectangular range is colored. When omitted, only the single cell at Row1, Col1 is affected.
 
Rows and columns are one-based arrays.
 
Parameter
Description
Row1
Long integer, required. The first row of the range.
Col1
Integer, required. The first column of the range.
InteriorColor
Long integer, optional. Background (fill) color. Use -1 to leave unchanged. Default value is -1.
FontColor
Long integer, optional. Text color. Use -1 to leave unchanged. Default value is -1.
BorderColor
Long integer, optional. Border color applied to all four edges (left, top, right, bottom) with continuous line style. Use -1 to leave unchanged. Default value is -1.
Row2
Long integer, optional. The last row of the range. When -1 (default), Row1 is used (single row).
Col2
Integer, optional. The last column of the range. When -1 (default), Col1 is used (single column).
 
See Also
Example
Sub Main
Dim x As Integer
 
If Not XLS.AppInit() Then Exit Sub
 
XLS.AppVisible = True
XLS.AddWorkBook
XLS.AddWorkSheet "ColorDemo"
 
'--- Header row: blue background, white text
For x = 1 To 5
XLS.SetValue 1, x, "Column " & CStr(x), True
Next x
XLS.SetColor 1, 1, vbBlue, vbWhite, , , 5
 
'--- Highlight a single cell with yellow background
XLS.SetValue 3, 2, "Important"
XLS.SetColor 3, 2, vbYellow
 
'--- Color a range with custom RGB, red border
XLS.SetColor 5, 1, RGB(240, 248, 255), , RGB(255, 0, 0), 8, 3
 
XLS.AppClose
End Sub