|
本帖最后由 413191246se 于 2015-5-15 20:35 编辑
鉴于整个宇宙搜索不到《如何判断表格是否规则》(所谓规则,就是没有拆分,没有合并的自然表格),所以,昨天中午起,到现在,独家研制成功《表格判断是否规则》宏!
好东西不能独享,所以发布出来,以享众位,敬请批评指正!(附件中有示例文档和代码,大家可以下载练习;另外,附赠:表格处理(通用)宏代码。)
*************************更新情况:考虑到一行表格的特例,加入条件假设。Sub 表格判断是否规则()
'x=最大行数,y=最大列数,s=当前表格单元格数目,e=1=规则表格,e=0=不规则表格
If Selection.Information(wdWithInTable) = False Then MsgBox "请将光标放在表格中!", vbOKOnly + vbCritical, "表格判断是否规则": End
Dim t As Table, x As Long, y As Long, s As Long, j As Long, k As Long, e As Long
Set t = Selection.Tables(1)
x = t.Range.Information(wdEndOfRangeRowNumber)
y = t.Range.Information(wdEndOfRangeColumnNumber)
s = t.Range.Cells.Count
If x <> 1 Then
If s = x * y Then
For k = 1 To y
For j = 1 To x - 1
If t.Cell(j + 1, k).Width = t.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
If e = 1 Then MsgBox "规则表格!": t.Range.Font.Color = wdColorBlue Else MsgBox "不规则表格!": t.Range.Font.Color = wdColorRed
End Sub
********************表格处理(通用)宏代码(只须将代码中 '格式处理 这行替换为自己的具体代码即可处理单独或所有表格):
Sub 表格处理()
'功能:光标在表格中处理当前表格;否则处理所有表格!
Dim t As Table, i As Long
If Selection.Information(wdWithInTable) = True Then i = 1
For Each t In ActiveDocument.Tables
If i = 1 Then Set t = Selection.Tables(1)
t.Select
Selection.Font.Color = wdColorBlue '格式处理
If i = 1 Then Exit For
Next
End Sub
|
|