Hide Only a Section of Table

D

DGjr.

Hi. I'm trying to find/write vba script that will hide only a select number
of rows from a table - so that I deselect a checkbox and it hides say, 10
rows below it. I've found the following code, but it hides ALL rows
underneath it. I only want some. Can someone help me?

Private Sub CheckBox1_Change()
Call ShowHideTable
End Sub

Sub ShowHideTable()
With Selection
.GoTo What:=wdGoToTable, Which:=wdGoToNext, _
Count:=1, Name:=""
.Tables(1).Select
End With
If CheckBox1.Value = True Then
With Selection.Font
.Hidden = False
End With
With ActiveWindow.View
.ShowHiddenText = True
.ShowAll = True
End With
Else
With Selection.Font
.Hidden = True
End With
With ActiveWindow.View
.ShowHiddenText = False
.ShowAll = False
End With
With Selection
.Collapse direction:=wdCollapseStart
.MoveLeft unit:=wdCharacter, Count:=1
End With
End If
End Sub
 
D

Dave Lett

Hi,

You can try something like the following:

Dim oTbl As Table
Dim oRng As Range
Set oTbl = ActiveDocument.Tables(1)
Set oRng = ActiveDocument.Range(Start:=oTbl.Rows(2).Range.Start, _
End:=oTbl.Rows(5).Range.End)
oRng.Font.Hidden = True

HTH
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top