|
https://club.excelhome.net/threa ... tml?_dsign=a9563e02
试一下这个
Sub 找出拆分的单元格且合并()
Dim tbl As Table
Dim cell As cell
Dim i, j, errorCount, 开始错误的行号, zonghang, zonglie As Integer
Dim a As Double
Set tbl = ActiveDocument.Tables(1)
zonghang = ActiveDocument.Tables(1).Rows.count
zonglie = ActiveDocument.Tables(1).Rows.count
For j = 1 To zonglie
On Error Resume Next ' 启用错误处理
For i = 1 To zonghang
tbl.cell(i, j).Select
If Err.Number <> 0 Then
If errorCount = 0 Then
开始错误的行号 = i - 1
End If
' 错误计数器 +1
errorCount = errorCount + 1
' 清除错误
Err.Clear
End If
Next i
On Error GoTo 0 ' 禁用错误处理
If 开始错误的行号 <> 0 Then
MsgBox ("合并的单元格在:第1个表格的第" & 开始错误的行号 & "行第" & j & "列,而且合并了" & errorCount + 1 & "行")
tbl.cell(开始错误的行号, j).Select
Call 拆分单元格(errorCount + 1, 1)
' MsgBox ("已经合并:第1个表格的第" & 开始错误的行号 & "行第" & j & "列,合并了" & errorCount + 1 & "行")
Else
' MsgBox ("在第" & j & "列中未找到合并的单元格")
End If
errorCount = 0
Next j
End Sub
Function 拆分单元格(Rows, Coluns)
Selection.Cells.Split NumRows:=Rows, NumColumns:=Coluns, MergeBeforeSplit:=False
End Function
|
|