每当我更新文档时,我都需要将一行添加到表的顶部,就在标题下面,然后将旧行移到下一个级别。表格通常出现在Word文档的最后一页。请找到随附的屏幕截图的预期和实际的行为。下面是我编写的实现代码:
期望:
我的代码:
亚Macro1()
Selection.EndKey Unit:=wdStory
Dim theTable As Table
Dim theNewRow As Row
For Each theTable In ActiveDocument.Tables
Set theNewRow = theTable.Rows.Add(theTable.Rows.First)
'Other row formatting
Next theTable
结束子对象
我正在学习VBA,任何帮助都是非常有用的。耽误您时间,实在对不起。
发布于 2020-11-09 10:31:04
正如Intellisense所显示的,[BeforeRow]
.是Table.Rows.Add
的输入参数这是一个可选参数,因此如果省略,则在表的最后一行之后添加新行。
由于您希望行在第一行之后,而在第二行之前,您需要将第二行作为参数传递。
With ActiveDocument.Tables(ActiveDocument.Tables.Count)
With .Rows.Add(.Rows(2))
'add date
.Cells(2).Range.Text = Format(Date, "MMMM d, yyyy")
'add any additional row formatting
End With
End With
发布于 2020-11-09 06:58:29
例如:
With ActiveDocument
With .Tables(.Tables.Count)
.Split (2)
With .Range.Characters.Last.Next
.FormattedText = .Next.Rows(1).Range.FormattedText
End With
.Rows(2).Range.Delete
End With
End With
但是,您所说的“将现有的行移到下一个级别”的含义还不清楚。
发布于 2020-11-09 08:04:38
它需要next。
Sub test()
Selection.EndKey Unit:=wdStory
Dim theTable As Table
Dim theNewRow As Row
For Each theTable In ActiveDocument.Tables
Set theNewRow = theTable.Rows.Add(theTable.Rows.First.Next) '<~~ add next
'Other row formatting
Next theTable
End Sub
https://stackoverflow.com/questions/64746757
复制相似问题