excel 边线快速修改,不用学哦

Sub Change() ‘中等改粗边线
Dim rng As Range, cell As Range
Dim borderIndexes As Variant
Dim i As Integer, progress As Long, totalCells As Long
Dim border As border
‘定义所有可能的边框位置
borderIndexes = Array(xlEdgeLeft, xlEdgeTop, xlEdgeBottom, xlEdgeRight, _
xlInsideHorizontal, xlInsideVertical)
‘获取当前工作表的已使用区域
Set rng = ActiveSheet.UsedRange
totalCells = rng.Cells.count
progress = 0
Application.ScreenUpdating = False
Application.StatusBar = “开始修改边框粗细…”
For Each cell In rng
For i = LBound(borderIndexes) To UBound(borderIndexes)
Set border = cell.Borders(borderIndexes(i))
‘仅当该边框存在(即不是无边框)时修改
If border.LineStyle <> xlLineStyleNone Then
‘‘边框线型
‘粗细程度 VBA常量 数值
‘极细 xlHairline 1
‘细 xlThin 2
‘中等 xlMedium – 4138
‘粗 xlThick 4
Select Case border.Weight
Case xlMedium ‘ 中等 → 粗
border.Weight = xlThick
Case xlThin ‘ 细 → 中等
border.Weight = xlMedium
‘其他粗细(xlHairline, xlThick)不做改动
End Select
End If
Next i
progress = progress + 1
If progress Mod 100 = 0 Then
Application.StatusBar = “正在处理: ” & progress & “/” & totalCells
End If
Next cell
Application.StatusBar = False
Application.ScreenUpdating = True
MsgBox “边框粗细修改完成!共处理 ” & totalCells & ” 个单元格。”, vbInformation
End Sub
夜雨聆风