Hello!
I was using the below VBA with documents and it was working like a charm...
However, I slightly modified the documents (included tables created from a different source) and now I get an error which highlights the below line:
How do I modify the code so that if it can't identify a table/row properly, it just skips until the next one? I don't need the VBA to run on the new tables, just on the previous ones.
Many thanks!
I was using the below VBA with documents and it was working like a charm...
Sub DelBlankRows()
Dim Pwd As String, pState As Boolean, Tbl As Table, oRow As Row
Dim oCel As Cell, Rng As Range, Fld As FormField, Str As String
With ActiveDocument
pState = False
If .ProtectionType <> wdNoProtection Then
Pwd = InputBox("Please enter the Password", "Password")
pState = True
.Unprotect Pwd
End If
For Each Tbl In .Tables
For Each oRow In Tbl.Rows
Str = vbNullString
For Each oCel In oRow.Cells
Set Rng = oCel.Range
With Rng
.End = .End - 1
If .FormFields.Count > 0 Then
For Each Fld In Rng.FormFields
Str = Str & Trim(Fld.Result)
Next
Else
Str = Str & Trim(.Text)
End If
End With
Next
If Str = vbNullString Then
On Error Resume Next 'skip vertically merged cells
oRow.Delete
End If
Next oRow
Next Tbl
If pState = True Then .Protect Type:=wdAllowOnlyFormFields, Noreset:=True, Password:=Pwd
pState = False: Pwd = vbNullString: Set Rng = Nothing
End With
End Sub
However, I slightly modified the documents (included tables created from a different source) and now I get an error which highlights the below line:
For Each oRow In Tbl.Rows
How do I modify the code so that if it can't identify a table/row properly, it just skips until the next one? I don't need the VBA to run on the new tables, just on the previous ones.
Many thanks!