1、编写绘制边框的程序:'绘制置单元格边框Public Sub unitBorder() With Selection.B泠贾高框orders(xlEdgeLeft) '设置左边框 .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) '设置上边框 .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) '设置下边框 .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) '设置右边框 .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End WithEnd Sub
2、运行以上程序可以对选择的单元格绘制边框。编写下面程序进行示范:Sub drawingborder()Sheets("Sheet1").SelectDim ws As WorksheetSet ws = ThisWorkbook.Worksheets("sheet1")Range(Cells(2, 1), Cells(4, 1)).Select: unitBorderEnd Sub
3、运行以上程序,在A2至A4单元格绘制边框。结果如下:
4、利用with语句可以简化表格绘制程序的编写,对于制表类的程序编写非常有用。