在包含多段单元格的Word表中向下移动一行 [英] Moving down a row in a Word table containing multi-paragraph cells
问题描述
如何可靠地向下移动Word表中的行?
这是表格的结构.请注意,第一列和第二列都可以具有多行和多段.
How can I reliably move down the rows in a Word table?
Here's the structure of the table. Note that the first and second columns can both have multiple lines and paragraphs.
Rule ID 1
Logic Date must be equal to or greater than 01-Jan-2012
Discrepancy Date is before 01-Jan-2012
message
Test case 1.1 Create form where Date is before 01-Jan-2012
Verify discrepancy message appears.
Print form.
Test case 1.2 Create form where Date is equal to 01-Jan-2012.
Verify no discrepancy message appears.
Print form.
Test case 1.3 Create form where Date is after 01-Jan-2012.
Verify no discrepancy message appears.
Print form.
我已经尝试了多种方法来降低表的位置.
I have tried a number of methods to move down the table.
当我尝试对Selection.MoveDown
和unit:=wdLine
(如下)进行操作时,当第1列包含自动换行时,我遇到了问题.
When I tried Selection.MoveDown
with unit:=wdLine
(below) I ran into problems when column 1 contained a word wrap.
Selection.MoveDown unit:=wdLine, Count:=1, Extend:=wdMove
当我尝试对unit:=wdParagraph
(如下)进行Selection.MoveDown
时,当第2列包含多个段落时,我遇到了问题.
When I tried Selection.MoveDown
with unit:=wdParagraph
(below), I ran into problems when column 2 contained multiple paragraphs.
Selection.MoveDown unit:=wdParagraph, Count:=3
unit:=wdRow
似乎不是Selection.MoveDown
的有效参数.
Selection.Cells(1).RowIndex
是只读参数
unit:=wdRow
does not appear to be a valid parameter for Selection.MoveDown
.
Selection.Cells(1).RowIndex
is a read-only parameter
有人知道一种简单的方法可以一次将表格向下移动一行,这种方式既可以处理第1列中的自动换行,也可以处理第2列中的多个段落.
Does anyone know of a simple method to move down the table one row at a time that would handle both the word wraps in column 1 and the multiple paragraphs in column 2?
推荐答案
尝试类似的方法.这是用于遍历Word文档中所有表的每一行和每一列的通用算法.根据需要进行修改(未测试的代码):
Try something like this. It's a generalized algorithm for looping through each row and column of all the tables in a Word document. Modify as needed (untested code):
Sub ModifyAllTables()
Dim oTbl As Table
Dim oRow As Row
Dim oRng As Range
For Each oTbl In ActiveDocument.Tables
For Each oRow In oTbl.Rows
' Select the cell in column 2.
Set oRng = oRow.Cells(2).Range
' and do something with it...
'e.g. oRng.TypeText "modified"
Next
Next
End Sub
这篇关于在包含多段单元格的Word表中向下移动一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!