|
前几天看到一个朋友圈的文章,里边将的是如何做一个具有国际标准的表格,其实就是如何美化表格,才能达到一个舒服的感觉,我觉得他的设置挺好看的,特地做了这个一键生成的代码,为一些患懒癌的朋友提供一剂强心剂,源于这个综合VBA 和表格设置,暂且放在这个版块
代码:
Sub 常用表格设置()
ActiveWindow.DisplayGridlines = False
ActiveCell.CurrentRegion.Borders.LineStyle = xlNone
n = ActiveCell.CurrentRegion.Rows.Count
For i = 1 To n
With ActiveCell.CurrentRegion.Rows(i)
If i = 1 Then
.Font.Name = "黑体"
With .Borders(xlEdgeBottom)
.Weight = xlMedium
End With
Else
If i = n Then
.Font.Bold = True
With .Borders(xlEdgeTop)
.ColorIndex = 0
.Weight = xlThin
End With
With .Borders(xlEdgeBottom)
.ColorIndex = 0
.Weight = xlThin
End With
Else
If i <> n Then
With .Borders(xlEdgeBottom)
.ThemeColor = 1
.TintAndShade = -0.249946592608417
End With
End If
If Application.IsOdd(i) Then
With .Interior
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
End With
End If
End If
End If
End With
Next i
m = ActiveCell.CurrentRegion.Columns.Count
For i = 1 To m
If VBA.IsNumeric(ActiveCell.CurrentRegion.Cells(n, i)) And ActiveCell.CurrentRegion.Cells(n, i) <> "" Then p = i: Exit For
Next i
With ActiveCell.CurrentRegion.Cells(1, 1).Resize(n, p - 1)
.HorizontalAlignment = xlLeft
End With
With ActiveCell.CurrentRegion.Cells(n, 1).Resize(1, p - 1)
.Merge
.HorizontalAlignment = xlCenter
End With
With ActiveCell.CurrentRegion.Cells(1, m - p - 1).Resize(1, m - p + 2)
.HorizontalAlignment = xlRight
End With
With ActiveCell.CurrentRegion.Cells(2, m - p - 1).Resize(n - 1, m - p + 2)
.Style = "Comma"
.Font.Name = "Arial Unicode MS"
End With
End Sub
|
|