2013-01-14 68 views
1

如何可靠地向下移动Word表格中的行?
这是表格的结构。请注意,第一列和第二列都可以有多行和多段。在包含多段落单元格的Word表格中向下移动一行

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. 

我已经尝试了许多方法向下移动表格。

当我试着Selection.MoveDownunit:=wdLine(下图)我遇到了问题,当列1包含自动换行。

Selection.MoveDown unit:=wdLine, Count:=1, Extend:=wdMove 

当我试图Selection.MoveDownunit:=wdParagraph(下同),我遇到了问题,当第2列含有多个段落。

Selection.MoveDown unit:=wdParagraph, Count:=3 

unit:=wdRow并不似乎是Selection.MoveDown一个有效的参数。
Selection.Cells(1).RowIndex是只读参数

有谁知道一个简单的方法来同时将处理下移表中的一行的两个词在第1列和第2列的多个段落换行?

回答

3

尝试类似这样的东西。这是一种循环遍历Word文档中所有表的每行和每列的通用算法。根据需要修改(未经测试的代码):

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 
1
Sub NextRow() 

    Dim c As Long, r As Long 

    With Selection 
     'ignore if not in table 
     If .Information(wdWithInTable) Then 

      c = .Columns(1).Index 
      r = .Rows(1).Index 

      If .Rows(1).Parent.Rows.Count >= r + 1 Then 
       .Rows(1).Parent.Rows(r + 1).Cells(c).Range.Select 
      End If 
     End If 
    End With 

End Sub 
相关问题