【问题标题】:Moving down a row in a Word table containing multi-paragraph cells在包含多段单元格的 Word 表格中向下移动一行
【发布时间】:2012-12-28 22:07:55
【问题描述】:

如何可靠地向下移动 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 列中的多个段落?

【问题讨论】:

    标签: vba ms-word word-2010


    【解决方案1】:

    试试这样的。它是一种通用算法,用于循环遍历 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
    

    【讨论】:

      【解决方案2】:
      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
      

      【讨论】:

        猜你喜欢
        • 2023-03-31
        • 1970-01-01
        • 1970-01-01
        • 2017-12-08
        • 2016-11-14
        • 1970-01-01
        • 2014-10-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多