|
修改了一下代码,并增加了表格合并后列对齐处理。不选定内容时针对全文档,不考虑分页符- Sub test2()
- '只对以一个段落分隔的两个表格进行合并,并尝试对齐列,可仅针对选定区域
- Dim myRange As Range
- Dim aTable As Table
- Dim aCol As Column
- Dim c As Byte
- Dim i As Integer
-
- On Error Resume Next
- Application.ScreenUpdating = False
- Set myRange = IIf(Selection.Type = wdSelectionIP, ActiveDocument.Content, Selection.Range)
- For Each aTable In myRange.Tables
- With aTable.Range
- If .Next(wdParagraph, 2).Information(wdWithInTable) = True Then
- ' aTable.Rows.Last.Range.HighlightColorIndex = wdYellow '突出显示前一表格的最后一行
- If .Next(wdTable).Start > myRange.End Then Exit For
- With .Next(wdTable).Tables(1)
- '当前表格与下一表格列数相同且下一表格各行列数相同时调整下一表格列宽以对齐列
- If .Columns.Count = aTable.Columns.Count And .Uniform = True Then
- For Each aCol In .Columns
- c = c + 1
- aCol.Width = aTable.Columns(c).Width
- Next
- c = 0
- End If
- End With
- .Next(wdParagraph).Text = Empty
- i = i + 1
- End If
- End With
- Next
- Application.ScreenUpdating = True
- MsgBox "共合并了" & i & "个相邻的表格。"
- End Sub
复制代码 |
|