我想在单词2010上检测并跳过vba中的合并单元格。
我正在创建一个需要在第一列写入的宏,但我有一些合并的单元格而且我不想写入。 我找到的所有例子都是用于Excel。
我试图检测每行的列数,但这不起作用。我得到"Error 5991 table has vertically merged cells"
。
那么当我得到合并的单元格时,我怎么能跳过这一行呢?
Sub test()
Dim Ro As Integer, Col As Integer
'init
Count = 1
Col = 1
For Ro = 4 To ActiveDocument.Tables(4).Rows.Count
'format
If Count < 10 Then
flag = "0"
Else
flag = ""
End If
'detect merge
If ActiveDocument.Tables(4).Rows(Ro).Cells.Count = 9 Then
ActiveDocument.Tables(4).Cell(Ro, Col).Range.Text = "R" & flag & CStr(Count)
Count = Count + 1
Else
Ro = Ro + 1
End If
Next Ro
End Sub
答案 0 :(得分:0)
我找到了解决方案!
我用它来绕过错误:
错误GoTo ErrorHandler
的ErrorHandler: 如果Err.Number = 5991或Err.Number = 5941那么 Err.Clear 简历byebye 结束如果
For Ro = 4 To ActiveDocument.Tables(4).Rows.Count
[My ugly code]
#in my case i can use a cell to determinate if it's a my row is merged or not
If Len(ActiveDocument.Tables(4).Cell(line, 5).Range.Text) > 0 Then
[My Ugly Code]
BYEBYE:
Next Ro
希望我的解决方案可以帮助你...