在 ms word vba 中复制一个复杂的(双)table 行
duplicate a complex (double) table row in ms word vba
在 Microsoft Word 2010 中,假设我有一个带有 table 的模板,其中包含一些准备好的列 headers 和第一行。这一行很复杂——基本上它跨越了两行。它在第一行和第二行 "real" 中的列宽也不均匀。例如
我正在尝试用动态行数填充此 table,我需要像第一个一样。例如
到目前为止我所看到的将行添加到 table 的方法都使新行看起来像最后一行(或第一行 - 取决于你的操作方式) - 但我想要相同的功能扩展到两行,即新的两行看起来像最后两行。
我发现的唯一方法是使用剪贴板。我想避免剪贴板。也许有人能想到另一种方法?
有效的剪贴板代码:
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
谢谢
对不起,这是一个忘记你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
如果版主认为有必要,我可能会完全删除post
在 Microsoft Word 2010 中,假设我有一个带有 table 的模板,其中包含一些准备好的列 headers 和第一行。这一行很复杂——基本上它跨越了两行。它在第一行和第二行 "real" 中的列宽也不均匀。例如
有效的剪贴板代码:
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
谢谢
对不起,这是一个忘记你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
如果版主认为有必要,我可能会完全删除post