Private Sub SetLine(ByVal strStart As String, ByVal strEnd As String, ByVal xlsWS As Excel.Worksheet) Dim i As Integer
With xlsWS.Range(strStart & ":" & strEnd) On Error Resume Next For i = 7 To 12 .Borders(i).LineStyle = xlContinuous Next ' .Borders(xlEdgeLeft).LineStyle = xlContinuous ' .Borders(xlEdgeTop).LineStyle = xlContinuous ' .Borders(xlEdgeBottom).LineStyle = xlContinuous ' .Borders(xlEdgeRight).LineStyle = xlContinuous ' .Borders(xlInsideVertical).LineStyle = xlContinuous ' .Borders(xlInsideHorizontal).LineStyle = xlContinuous End With End Sub
Dim appExcel As New Excel.Application dim bsRange as range ... ... ... set bsRange =appExcel.ActiveSheet.Range("XXX") 'XXX为第一个有内容的单元格 with bsRange.CurrentRegion .Borders(xlEdgeBottom).Weight = xlContinuous .Borders(xlEdgeTop).Weight = xlContinuous .Borders(xlEdgeLeft).Weight = xlContinuous .Borders(xlEdgeRight).Weight = xlContinuous '内部水平划线 If .Rows.Count > 1 Then .Borders(xlInsideHorizontal).Weight = xlContinuous If .Columns.Count > 1 Then .Borders(xlInsideVertical).Weight = xlContinuous End With
Dim i As Integer
With xlsWS.Range(strStart & ":" & strEnd)
On Error Resume Next
For i = 7 To 12
.Borders(i).LineStyle = xlContinuous
Next
' .Borders(xlEdgeLeft).LineStyle = xlContinuous
' .Borders(xlEdgeTop).LineStyle = xlContinuous
' .Borders(xlEdgeBottom).LineStyle = xlContinuous
' .Borders(xlEdgeRight).LineStyle = xlContinuous
' .Borders(xlInsideVertical).LineStyle = xlContinuous
' .Borders(xlInsideHorizontal).LineStyle = xlContinuous
End With
End Sub
dim bsRange as range
... ... ...
set bsRange =appExcel.ActiveSheet.Range("XXX") 'XXX为第一个有内容的单元格
with bsRange.CurrentRegion
.Borders(xlEdgeBottom).Weight = xlContinuous
.Borders(xlEdgeTop).Weight = xlContinuous
.Borders(xlEdgeLeft).Weight = xlContinuous
.Borders(xlEdgeRight).Weight = xlContinuous
'内部水平划线
If .Rows.Count > 1 Then .Borders(xlInsideHorizontal).Weight = xlContinuous
If .Columns.Count > 1 Then .Borders(xlInsideVertical).Weight = xlContinuous
End With