【问题标题】:duplicate a complex (double) table row in ms word vba在 ms word vba 中复制复杂(双)表行
【发布时间】:2018-02-25 10:02:18
【问题描述】:

在 Microsoft Word 2010 中,假设我有一个带有表格的模板,其中包含一些准备好的列标题和第一行。这一行很复杂——基本上它跨越了两个真实的行。它在第一和第二“真实”行中也有不均匀的列宽。例如 我正在尝试使用动态行数填充此表,我需要像第一个一样。例如 到目前为止,我看到的将行添加到表中的方法都使新行看起来像最后一行(或第一行 - 取决于您执行此操作的方式) - 但我希望将相同的功能扩展到两个行,即新的两行看起来像最后两行。 我发现的唯一方法是使用剪贴板。我想避免剪贴板。也许任何人都可以想到另一种方式?

有效的剪贴板代码:

Sub example()

    Set myrows = ActiveDocument.Range( _
        ActiveDocument.Tables.Item(1).Rows.Item(1).Range.Start, _
        ActiveDocument.Tables.Item(1).Rows.Item(2).Range.End _
    )

    myrows.Select

    ' this works
    myrows.Copy
    myrows.Paste

    ' this adds two rows that look like the last row in the selection
    ' this is not what i need
    'Selection.InsertRowsBelow

End Sub

谢谢

【问题讨论】:

    标签: vba ms-word office-interop office-2010


    【解决方案1】:

    对不起,这是一个忘记你在 10 年前学到的东西的例子。我提出的特定问题似乎很容易回答。

    Sub example()
    
        Set myrows = ActiveDocument.Range( _
            ActiveDocument.Tables.Item(1).Rows.Item(1).Range.Start, _
            ActiveDocument.Tables.Item(1).Rows.Item(2).Range.End _
        )
    
        ' this works
        Set rowsbelow = ActiveDocument.Range(myrows.End, myrows.End)
        rowsbelow.FormattedText = myrows.FormattedText
    
    End Sub
    

    如果版主认为有必要,我可以完全删除帖子

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-08
      相关资源
      最近更新 更多