乐于分享
好东西不私藏

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

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

本站文章均为手工撰写未经允许谢绝转载:夜雨聆风 » excel 边线快速修改,不用学哦

评论 抢沙发

2 + 5 =
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
×
订阅图标按钮