3種刪除Word表中空白行和列的快速方法

立即分享:

在這個post,我們將向您介紹3種刪除Word表中空白行和列的快速方法。

表對於文檔至關重要,尤其是在保存各種類型的數據時。 有時,一個長表可以超過一頁,並且可以擴展到幾頁。 因此,一旦表變得冗長而復雜,就可以採取一些措施來簡化它。 例如,您可以刪除不必要的空白行和列。刪除Word表中的空白行和列

以下是您可以使用的3種方法。

方法1:手動刪除空白行和列

  1. 首先,在空白處選擇一行或一列。
  2. 然後右鍵單擊以獲取上下文菜單。 在菜單上,相應地選擇“刪除行”或“刪除列”。選擇一個列->右鍵單擊->單擊“刪除列”

不幸的是,您不能選擇多個非連續的行或列並以此方式將它們一起刪除。 對於這種需求,您可以參考我們的上一篇文章: 5種快速刪除Word表中多行或多列的快速方法

方法2:批量刪除表中的所有空白行和列

方法1有其局限性。 因此,我們將為您提供通過VBA代碼批量刪除表中行和列的方法。

  1. 首先,將光標放在 tar拿桌子。
  2. 其次,按“ Alt + F11”觸發VBA編輯器。
  3. 在編輯器中,首先單擊“普通”項目。
  4. 然後單擊菜單欄上的“插入”選項卡。
  5. 在下拉菜單上,選擇“模塊”。單擊“常規”->單擊“插入”->單擊“模塊”
  6. 雙擊模塊以將其打開並在其中粘貼以下代碼:
Sub DeleteBlankRowsAndTablesInATable()
  Dim objCell As Cell
  Dim nRowIndex As Integer, nRows As Integer, nColumns As Integer, nColumnIndex As Integer
  Dim varCellEmpty As Boolean
 
  Application.ScreenUpdating = False
 
  If Selection.Information(wdWithInTable) = False Then
    MsgBox ("Put cursor inside a table first!")
    Exit Sub
  Else
    With Selection.Tables(1)
      nRows = .Rows.Count
      For nRowIndex = nRows To 1 Step -1
        varCellEmpty = True
        For Each objCell In .Rows(nRowIndex).Cells
          If Len(objCell.Range.Text) > 2 Then
            varCellEmpty = False
            Exit For
          End If
        Next objCell
          If varCellEmpty = True Then
            .Rows(nRowIndex).Delete
          End If
      Next nRowIndex
 
      nColumns = .Columns.Count
      For nColumnIndex = nColumns To 1 Step -1
        varCellEmpty = True
        For Each objCell In .Columns(nColumnIndex).Cells
          If Len(objCell.Range.Text) > 2 Then
            varCellEmpty = False
            Exit For
          End If
        Next objCell
          If varCellEmpty = True Then
            .Columns(nColumnIndex).Delete
          End If
      Next nColumnIndex
    End With
  End If

  Set objCell = Nothing

  Application.ScreenUpdating = True
End Sub
  1. 最後,單擊菜單欄上的“運行”按鈕或單擊“ F5”。粘貼代碼->單擊“確定”

在幾秒鐘內,您將刪除該表中的所有空白行和列。

方法3:批量刪除文檔中所有表中的所有空白行和列

  1. 首先,重複方法2中的步驟以安裝和運行宏。
  2. 僅這次,用以下命令替換該宏:
Sub DeleteBlankRowsAndColumnsInAllTables()
  Dim objCell As Cell
  Dim objTable As Table
  Dim nRowIndex As Integer, nRows As Integer, nColumns As Integer, nColumnIndex As Integer
  Dim varCellEmpty As Boolean
 
  Application.ScreenUpdating = False
 
  With ActiveDocument
    For Each objTable In .Tables
      nRows = objTable.Rows.Count
      For nRowIndex = nRows To 1 Step -1
        varCellEmpty = True
        For Each objCell In objTable.Rows(nRowIndex).Cells
          If Len(objCell.Range.Text) > 2 Then
            varCellEmpty = False
            Exit For
          End If
        Next objCell
          If varCellEmpty = True Then
            objTable.Rows(nRowIndex).Delete
          End If
      Next nRowIndex
    Next objTable
 
    For Each objTable In .Tables
      nColumns = objTable.Columns.Count
      For nColumnIndex = nColumns To 1 Step -1
        varCellEmpty = True
        For Each objCell In objTable.Columns(nColumnIndex).Cells
          If Len(objCell.Range.Text) > 2 Then
            varCellEmpty = False
            Exit For
          End If
        Next objCell
          If varCellEmpty = True Then
            objTable.Columns(nColumnIndex).Delete
          End If
      Next nColumnIndex
    Next objTable
  End With

  Set objCell = Nothing
  Set objTable = Nothing

  Application.ScreenUpdating = True
End Sub

恢復損壞的文檔

檢索l的方法不止一種ost 如今的數據。 例如,求助始終是您的頭等大事。 如果這樣不能滿足您獲取最新信息的需求,則可以嘗試 doc修復 工具。

作者簡介:

陳薇薇(Vera Chen)是 DataNumen,Inc.是數據恢復技術的全球領導者,包括 xlsx維修 以及 pdf 維修軟件產品。 欲了解更多信息,請訪問 萬維網。datanumen.COM

立即分享:

評論被關閉。