gisoracle

View Post

如何用vba给一个word表格的最后插入一行

Sub Example()
    Dim myTable As Table
    Set myTable = ActiveDocument.Tables(1)
    myTable.Rows.Last.Select
    Selection.InsertRowsBelow 1
End 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 myLastRow
End 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 myRows
End Sub


来自http://club.excelhome.net/viewthread.php?tid=205161

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-27
  • 2021-12-10
  • 2022-12-23
  • 2021-10-14
  • 2021-04-08
  • 2021-11-15
  • 2022-12-23
猜你喜欢
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2021-07-10
  • 2022-12-23
相关资源
相似解决方案