|
楼主,表格固定值20磅,文字将不再居中!所以,恕难从命,表格仍为单倍行距,这样文字上下左右才居中。请试试如下代码(并非完美,勉强先用用吧!):
- Sub test表格样式()
- Dim t As Table, c As Cell, i As Paragraph, j&, k&, x&, y&, z&, e&
- For Each t In ActiveDocument.Tables
- With t
- With .Range '探测表格是否规则(e=1=规则,e=0=不规则)
- .Find.Execute "^13", , , 0, , , , , , "^p", 2
- .Find.Execute "^11", , , 0, , , , , , "^p", 2
- x = .Information(wdEndOfRangeRowNumber)
- y = .Information(wdEndOfRangeColumnNumber)
- z = .Cells.Count
- End With
- If x <> 1 Then
- If z = x * y Then
- For k = 1 To y
- For j = 1 To x - 1
- If .Cell(j + 1, k).Width = .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 .Rows
- .WrapAroundText = False
- .Alignment = wdAlignRowLeft
- .LeftIndent = CentimetersToPoints(0)
- .HeightRule = wdRowHeightAtLeast
- .Height = CentimetersToPoints(0.8)
- End With
- .LeftPadding = CentimetersToPoints(0.19)
- .RightPadding = CentimetersToPoints(0.19)
- .Select
- Selection.MoveDown 4, 1, 1
- CommandBars.FindControl(ID:=122).Execute
- CommandBars.FindControl(ID:=123).Execute
- .Select
- Selection.ClearFormatting
- With .Range
- With .Font
- .Kerning = 0
- .DisableCharacterSpaceGrid = True
- End With
- With .ParagraphFormat
- .CharacterUnitFirstLineIndent = 0
- .FirstLineIndent = CentimetersToPoints(0)
- .LineSpacingRule = wdLineSpaceSingle
- .Alignment = wdAlignParagraphCenter
- .AutoAdjustRightIndent = False
- .DisableLineHeightGrid = True
- ' .LineSpacingRule = wdLineSpaceExactly'固定值20磅
- ' .LineSpacing = 20
- End With
- .Cells.VerticalAlignment = wdCellAlignVerticalCenter
- End With
- .AutoFitBehavior (wdAutoFitContent) '根据内容调整表格
- .AutoFitBehavior (wdAutoFitContent)
- .Select
- .AutoFitBehavior (wdAutoFitWindow) '根据窗口调整表格
- .AutoFitBehavior (wdAutoFitWindow)
- '规则表格表头加粗(表头即表格第一行)
- If e = 1 Then
- If Len(.Cell(2, 1).Range) > 2 Then
- With .Rows(1).Range.Font
- .Name = "黑体"
- .Name = "Times New Roman"
- .Bold = True
- .Color = wdColorRed
- End With
- End If
- End If
- '删除单元格内空行
- For Each c In .Range.Cells
- For Each i In c.Range.Paragraphs
- If Asc(i.Range) = 13 And Len(i.Range) = 1 Then i.Range.Delete
- Next
- With c.Range.Paragraphs
- If .Count > 1 And Len(.Last.Range) = 2 Then
- .Last.Previous.Range.Characters.Last.Delete
- End If
- End With
- Next
- End With
- Next
- End Sub
复制代码 |
|