|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 表格排版()
Dim t As Table, x As Long, y As Long, s As Long, j As Long, k As Long, e As Long
For Each t In ActiveDocument.Tables
x = t.Range.Information(wdEndOfRangeRowNumber)
y = t.Range.Information(wdEndOfRangeColumnNumber)
s = t.Range.Cells.Count
If x <> 1 Then
If s = x * y Then
For k = 1 To y
For j = 1 To x - 1
If t.Cell(j + 1, k).Width = t.Cell(j, k).Width Then e = 1 Else e = 0
If e = 0 Then Exit For
Next j
If e = 0 Then Exit For
Next k
Else
e = 0
End If
Else
e = 1
End If
With t
With .Rows
.WrapAroundText = False
.Alignment = wdAlignRowLeft
.LeftIndent = CentimetersToPoints(0)
End With
With .Range
.Font.Size = 12
With .ParagraphFormat
.CharacterUnitFirstLineIndent = 0
.FirstLineIndent = CentimetersToPoints(0)
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphCenter
End With
.Cells.VerticalAlignment = wdCellAlignVerticalCenter
End With
If .LeftPadding <> CentimetersToPoints(0.19) Then .LeftPadding = CentimetersToPoints(0.19)
If .RightPadding <> CentimetersToPoints(0.19) Then .RightPadding = CentimetersToPoints(0.19)
If e = 1 Then
If x > 1 Then
With .Rows(1).Range.Font
.Name = "黑体"
.Name = "Times New Roman"
.Bold = True
End With
End If
With .Rows
.HeightRule = wdRowHeightAtLeast
.Height = CentimetersToPoints(0.7)
End With
.AutoFitBehavior (wdAutoFitContent)
.AutoFitBehavior (wdAutoFitContent)
.Select
End If
.AutoFitBehavior (wdAutoFitWindow)
.AutoFitBehavior (wdAutoFitWindow)
'add
.Select
Selection.Next(Unit:=wdParagraph, Count:=1).Select
CommandBars.FindControl(ID:=122).Execute
CommandBars.FindControl(ID:=123).Execute
If Len(Selection) <> 1 Then
Selection.HomeKey Unit:=wdLine
Selection.InsertParagraphBefore
Selection.Font.Size = 4
End If
End With
Next
End Sub |
|