|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
请教:TypeText "* 表格满页:运行好慢。有好多重复步骤工作。能否简单一下。有些相同项在里面,真心看不懂。想学习
Sub 表格满页()
' 如果光标在表格中,则处理光标所在表格;否则,将处理所有表格!
' 仅适用于将规则表格扩展或缩减为一页!不适用于跨页排版(可按Ctrl+Break键结束宏)
On Error Resume Next
Dim t As Table, n As Long, myTable As Table, FirstPage As Integer, LastPage As Integer, i As Long, j As Single, k As Single
If Selection.Information(wdWithInTable) = True Then Selection.Tables(1).Select: n = 1
For Each t In ActiveDocument.Tables
If n = 1 Then Set t = Selection.Tables(1) Else t.Select
' Macro 表格满页_单个
Set myTable = Selection.Tables(1)
' 初始行高
Selection.Tables(1).Select
Selection.Rows.HeightRule = wdRowHeightAtLeast '最小值
Selection.Rows.Height = CentimetersToPoints(0.5)
Do
''' 判断表格是否跨页(code by 守柔版主)
With myTable
FirstPage = .Cell(1, 1).Range.Information(wdActiveEndPageNumber)
LastPage = .Range.Cells(.Range.Cells.Count).Range.Information(wdActiveEndPageNumber)
If LastPage <> FirstPage Then
i = 2
Else
i = 1
End If
End With
'''
j = j + 0.02
If i = 1 Then
Selection.Tables(1).Select
Selection.Rows.HeightRule = wdRowHeightAtLeast '最小值
Selection.Rows.Height = CentimetersToPoints(0.5 + j)
ElseIf i = 2 Then
Exit Do
End If
Loop
' 当前行高
k = Round(Selection.Rows.Height / 28.35, 2)
j = 0
Do
'''判断表格是否跨页(code by 守柔版主)
With myTable
FirstPage = .Cell(1, 1).Range.Information(wdActiveEndPageNumber)
LastPage = .Range.Cells(.Range.Cells.Count).Range.Information(wdActiveEndPageNumber)
If LastPage <> FirstPage Then
i = 2
Else
i = 1
End If
End With
'''
j = j + 0.01
If i = 2 Then
Selection.Tables(1).Select
Selection.Rows.HeightRule = wdRowHeightExactly '固定值
Selection.Rows.Height = CentimetersToPoints(k - j)
Selection.Rows.HeightRule = wdRowHeightAtLeast '最小值
Selection.Rows.Height = CentimetersToPoints(k - j)
ElseIf i = 1 Then
Exit Do
End If
Loop
If n = 1 Then Exit For
Next
End Sub |
|