Share via

Hide blank table rows

Anonymous
2012-07-31T08:09:59+00:00

I need to hide tables and table rows with VBA.

Hiding text with .Font.Hidden is not a problem. However when I print the document, there are many blank table rows. Is there a way to hide them?

Thank you!

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2012-07-31T08:33:00+00:00

I need to hide tables and table rows with VBA.

Hiding text with .Font.Hidden is not a problem. However when I print the document, there are many blank table rows. Is there a way to hide them?

Thank you!

Use a macro containing the following code:

Dim i As Long, j As Long, n As Long

Dim blnhide As Boolean

Dim strDoc As String

With ActiveDocument

    strDoc = .FullName

    For i = .Tables.Count To 1 Step -1

        With .Tables(i)

            For j = .Rows.Count To 1 Step -1

                With .Rows(j)

                    For n = 1 To .Cells.Count

                        If .Cells(n).Range.Font.Hidden = True Then

                            blnhide = True

                        Else

                            blnhide = False

                        End If

                    Next n

                    If blnhide = True Then

                    .Delete

                End With

            Next j

        End With

    Next i

    .PrintOut

    .Close wdDoNotSaveChanges

End With

Documents.Open (strName)

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2012-07-31T08:23:06+00:00

    You might be able to use the HideMark Class, though I'm not sure it works in Office 2007. See: http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.hidemark.aspx

    For a discussion of a document containing such a table, see: http://www.eileenslounge.com/viewtopic.php?f=26&t=10224

    Was this answer helpful?

    0 comments No comments