|
请试试我的代码,就能删除表格中某个段落上方的空段。
- Sub 表格处理()
- Dim t As Table, c As Cell, i&, j&, k&, x&, y&, z&, e&, s As Paragraph, v&, u As Range, w&
- For Each s In ActiveDocument.Paragraphs
- If s.Range.Style = "正文" Then v = s.Range.Font.Size: Exit For
- Next
- If Selection.Information(wdWithInTable) = True Then i = 1
- For Each t In ActiveDocument.Tables
- If i = 1 Then Set t = Selection.Tables(1)
- With t
- With .Range
- 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)
- If e = 1 Then
- .HeightRule = wdRowHeightAtLeast
- .Height = CentimetersToPoints(0.9)
- End If
- End With
- If .LeftPadding <> CentimetersToPoints(0.19) Then .LeftPadding = CentimetersToPoints(0.19)
- If .RightPadding <> CentimetersToPoints(0.19) Then .RightPadding = CentimetersToPoints(0.19)
- With .Range
- .Find.Execute "^l", , , 0, , , , , , "^p", 2
- .Find.Execute "^13", , , 0, , , , , , "^p", 2
- End With
- .Select
- Selection.MoveDown unit:=wdParagraph, Count:=1, Extend:=wdExtend
- CommandBars.FindControl(ID:=122).Execute
- CommandBars.FindControl(ID:=123).Execute
- .Select
- Selection.ClearFormatting
- ' If e = 1 Then .Range.Font.Color = wdColorBlue Else .Range.Font.Color = wdColorRed
- With .Range
- With .Font
- If v = 16 Then
- .Name = "仿宋"
- .Name = "Times New Roman"
- End If
- .Size = 12
- .Kerning = 0
- .DisableCharacterSpaceGrid = True
- End With
- With .ParagraphFormat
- .CharacterUnitFirstLineIndent = 0
- .FirstLineIndent = CentimetersToPoints(0)
- .LineSpacingRule = wdLineSpaceSingle
- .Alignment = wdAlignParagraphCenter
- .AutoAdjustRightIndent = False
- .DisableLineHeightGrid = True
- 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
- w = c.Range.Paragraphs.Count
- If w > 1 Then
- Set u = ActiveDocument.Range(Start:=c.Range.Paragraphs(1).Range.Start, End:=c.Range.Paragraphs(w - 1).Range.End)
- For Each s In u.Paragraphs
- If Len(s.Range) = 1 Then s.Range.Delete
- Next
- If Len(c.Range.Paragraphs(c.Range.Paragraphs.Count).Range) = 2 Then
- If c.Range.Paragraphs.Count > 1 Then c.Range.Paragraphs(c.Range.Paragraphs.Count - 1).Range.Characters.Last.Delete
- End If
- End If
- Next
- End With
- If i = 1 Then Exit For
- Next
- End Sub
复制代码 |
|