如何select第二行到最后一行的范围字VBA

How to select a range of the second row to the last row Word VBA

我目前正在使用 Microsoft Word VBA 并且需要帮助弄清楚如何 select 第二行一直到最后。我现在的代码是:

Set MyTable = ActiveDocument.Tables(3)

    'if not new table select all but first row, else select whole table
    If NewTable = 0 Then
        Selection.Start = Selection.Tables(3).Rows(2).Range.Start
    Else
        ActiveDocument.Tables(3).Select
    End If

我收到错误消息:

说它不存在。我肯定有 3 个表,因为我 运行 a Debug.Print Active.Document.Tables.Count 它说是三个。有任何想法吗?感谢您的帮助!

试试这个:

Sub SelectRows()
  Dim mytable As Table
  Set mytable = ActiveDocument.Tables(3)
  Dim NewTable As Boolean

  'if not new table select all but first row, else select whole table
  If NewTable = 0 Then
    With mytable
      ActiveDocument.Range(.Rows(2).Range.Start, .Rows(.Rows.Count).Range.End).Select
    End With
  Else
    myTable.Select
  End If

End Sub