您的位置:首页 > 编程语言 > VB

word合并单元格后,VBA读取设置相应单元格内容

2008-11-02 16:29 316 查看

'设置单元格的行列坐标并写的word文档中
Sub SetTablePosition()
Dim tbl As Table
Dim cell As cell
Dim tblIndex As Integer
Dim cellContent As String
'以下遍历表格中存在的单元格
For Each tbl In ThisDocument.Tables
tblIndex = tblIndex + 1
Row = 1
col = 1
Do While (1)
Set cell = tbl.cell(Row, col)
If Not cell Is Nothing Then '如果单元格存在
Debug.Print cell.RowIndex
Debug.Print cell.ColumnIndex

'TO-DO**********************************************************************
cell.Select
cellContent = Selection.Text
'If Len(Trim(content)) <> 0 Then GoTo nextCell
Selection.Text = "p" & Selection.Information(wdActiveEndPageNumber) _
& "t" & tblIndex & "r" & Row & "c" & col
'END**********************************************************************

Set cell = tbl.cell(cell.RowIndex, cell.ColumnIndex).Next
If cell Is Nothing Then Exit Do
cell.Select
Row = cell.RowIndex
col = cell.ColumnIndex
Set cell = tbl.cell(Row, col)
Else
Exit Do
End If
nextCell: Loop
Next
End Sub
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: