Friday, April 2, 2010

VBScript - Putting Borders Around Spreadsheet Cells

VBScript - Putting Borders Around Spreadsheet Cells

A complete script that puts a border around only cell B3.

Const xlContinuous = 1
Const xlThick = 4

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)

k = 1
For i = 1 to 5
For j = 1 to 5
objWorksheet.Cells(i,j) = k
k = k + 1
Next
Next

objWorksheet.Range("B3").Borders.LineStyle = xlContinuous
objWorksheet.Range("B3").Borders.Color = RGB(255, 0, 0)
objWorksheet.Range("B3").Borders.Weight = xlThick

[Via]