Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding and deleting empty rows in tables in Word 1

Status
Not open for further replies.

harky

Technical User
Oct 29, 2001
39
GB
Does anyone know how to determine whether or not a row in a Word table is empty and delete it?
 
Sub test()
Dim oRow As Row
Dim oCell As Cell
Dim oTable As Table
Dim nRowIndex As Long
Dim nCellCount As Long
Dim i As Long

For Each oTable In ActiveDocument.Tables
For nRowIndex = oTable.Rows.Count To 1 Step -1
Set oRow = oTable.Rows(nRowIndex)
nCellCount = oRow.Cells.Count
If oRow.Range.Text = EmptyRow(nCellCount) Then ' empty
oRow.Delete
Else
Debug.Print nRowIndex, "is not empty"
End If
Set oRow = Nothing
Next nRowIndex
Next oTable

Set oRow = Nothing
Set oTable = Nothing
End Sub

Private Function EmptyRow(ByVal nCellCount As Long) As String
Dim i As Long

For i = 1 To (nCellCount + 1)
EmptyRow = EmptyRow & Chr$(13) & Chr$(7)
Next i
End Function
 
Do you know how I can stop the code at the end of the document, it seems to be stuck in a continuous loop?
 
Can you post your code?
I tried my code on a sample file with lots of tables and it exits properly.
 
Sorry, my mistake. I think because the files I was working on were very large, it appeared to have crashed. But it's fine. Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top