Reputation: 13
I am currently working in Microsoft Word VBA and need help figuring out how to select the second row all the way down to the last. My code right now is:
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
and I am getting the error:
saying that it doesn't exist. I definitely have 3 tables as I ran a Debug.Print Active.Document.Tables.Count and it said three. Any ideas? Thank you for the help!
Upvotes: 0
Views: 2517
Reputation: 7850
Try this:
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
Upvotes: 1