vba代码-excel表格边框及格式设置

这是边框设置

Sub formatTables(ByVal oRng As Object)
oRng.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 = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    
End Sub

 这是格式设置

Sub formatCells()
    Dim oRng As Object
    Set oRng = Range("a3").CurrentRegion
    'oRng.ClearContents
    
    oRng.Select
    Selection.NumberFormatLocal = "0.00"
    
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
    End With
    With Selection.Font
        .Name = "Times New Roman"
        .Size = 11
        .Underline = xlUnderlineStyleNone
    End With
    
    Call formatTables(oRng)
    
End Sub

Sub clearCells()
    
    Set oRng = Range("a3").CurrentRegion
    oRng.ClearContents
    
    
End Sub

  

posted on 2022-08-07 16:06  风中狂笑  阅读(885)  评论(0编辑  收藏  举报

导航