如何用vba给一个word表格的最后插入一行 | 您所在的位置:网站首页 › word表格怎么加入一行 › 如何用vba给一个word表格的最后插入一行 |
Sub Example() Dim myTable As Table Set myTable = ActiveDocument.Tables(1) myTable.Rows.Last.Select Selection.InsertRowsBelow 1End Sub 用ActiveDocument.Tables(1).Rows.Add好像也行,不知两者的效果有没有区别。 ActiveDocument.Tables(1).Rows.Add方法总是在指定行的前面插入行。 如: Sub Example2() Dim myTable As Table, myLastRow As Row Set myTable = Me.Tables(1) Set myLastRow = myTable.Rows.Last myTable.Rows.Add myLastRowEnd Sub 而Selection对象可以在所选行的上方或者下方插入等量的行。 注意,Add方法也可以插入指定数量的行。 Sub Example3() Dim myTable As Table, myRows As Rows Set myTable = Me.Tables(1) Set myRows = Me.Range(myTable.Rows(1).Range.Start, myTable.Rows(3).Range.End).Rows myTable.Rows.Add myRowsEnd Sub 来自http://club.excelhome.net/viewthread.php?tid=205161 |
CopyRight 2018-2019 实验室设备网 版权所有 |