使用vba在word中处理表格时,有时要判断这一行表格是否为空白,无内容,以便中止或者跳过读取数据,编辑内容。
可以使用Table对象的Rows属性返回具体的行,然后判断第一个单元格无内容.再做下一步操作.
在word中,空白内容有回车符的段落标记显示,使用代码Chr(13) & Chr(7)表示。
Chr(7)表示数据末尾带制表符的黑点。
With wd.Documents.Open(mypath & myDOC)
n = .Tables(1).Rows.Count
For r = 2 To n
atext = Trim(.Tables(1).Cell(r, 2).Range.Text)
If atext = Chr(13) & Chr(7) Then '判断单元格内容是否为空
Exit For
Else
i = i + 1
Cells(i, 4) = .Tables(1).Cell(r, 2).Range 'Tables(2)即Word文档中第一个表格,Cell(1, 2)即第一行第二格中的内容
Cells(i, 5) = .Tables(1).Cell(r, 3).Range
Cells(i, 6) = .Tables(1).Cell(r, 4).Range
j = j + 1
End If
Next r
end with