0

以下代码成功删除了表中的选择。

If Selection.Information(wdWithInTable) Then
    Selection.Rows.Delete
End If

此外,以下代码成功地阻止了前两个表行的删除,但不基于选择从底行向上删除。

Dim index As Long
    For index = ActiveDocument.Tables(1).Rows.Count To 3 Step -1
        ActiveDocument.Tables(1).Rows(index).Delete
    Exit For
    Next index

有没有办法将两者结合起来,这样我就可以删除任何选定的行但防止前两行被删除?

4

1 回答 1

0

如果您清楚地说明您要达到的目标,那将会很有帮助。尝试以下方式:

Sub Demo()
With Selection
  If .Information(wdWithInTable) = False Then Exit Sub
  If .Cells(.Cells.Count).RowIndex > 2 Then
    If .Cells(1).RowIndex < 3 Then
      .Start = .Tables(1).Rows(3).Range.Start
    End If
    .Rows.Delete
  End If
End With
End Sub
于 2020-12-06T19:46:45.053 回答