小编Tri*_*ias的帖子

将所有边框添加到选定范围,是否有更短的编写代码的方法?

我将所有边框添加到某个范围,在我的情况下(A6:O6),在excel VBA中,下面的代码可以工作,但我想有必要用更短的方式来编写它.我发现了一行代码,它在整个选择周围放置了一个边框,但不是在每个单元格周围.

Range("A6:O6").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = …
Run Code Online (Sandbox Code Playgroud)

excel vba border excel-vba

1
推荐指数
2
解决办法
4579
查看次数

标签 统计

border ×1

excel ×1

excel-vba ×1

vba ×1