Dim xlApp As Excel.Application
Dim xlSheet As Excel.Worksheet
Dim xlWorkbook As Excel.Workbook
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWorkbook = xlApp.Workbooks.Add
Set xlSheet = xlWorkbook.Sheets(1)
With xlSheet.Range("A1:E1").Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With xlSheet.Range("A1,B1,C1,D1,E1").Borders(xlEdgeLeft)
或者使用循环:
Dim cell As Excel.Range
For Each cell in xlSheet.Range("A1:E1")
With cell.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
Next