Hidden rows appearing on open

N

Newt

I'm using the following VBA to hide rows based on the selected checkboxes.
However, if I close the document and then reopen it, the hidden rows appear,
but sort of squashed. Any ideas?

Sub AutoOpen()
Dim myArray1() As Variant
Dim myArray2() As Variant
myArray1 = Array("Regular", "24 Hour Priority", "Same Day Urgent")
With ComboBox1
..Clear
..List() = myArray1
End With

myArray2 = Array("Test1", "Test2", "Test3")
With ComboBox2
..Clear
..List() = myArray2
End With
End Sub

Private Sub CheckBox1_Click()
CheckBox1.Font.Bold = CheckBox1.Value
If CheckBox1.Value = False Then
CheckBox1.Font.Size = 10
ActiveDocument.Tables(1).Rows(2).Range.Font.Hidden = False

Else
CheckBox1.Font.Size = 12
ActiveDocument.Tables(1).Rows(2).Range.Font.Hidden = True

End If
End Sub

Private Sub CheckBox2_Click()
CheckBox2.Font.Bold = CheckBox2.Value
If CheckBox2.Value = False Then
CheckBox2.Font.Size = 10
ActiveDocument.Tables(1).Rows(1).Range.Font.Hidden = False
With ActiveDocument.Tables(1).Rows(2).Borders(wdBorderTop)
.LineStyle = wdLineStyleDot
.LineWidth = wdLineWidth025pt
.Color = wdColorGray25
End With
Else
CheckBox2.Font.Size = 12
ActiveDocument.Tables(1).Rows(1).Range.Font.Hidden = True
With ActiveDocument.Tables(1).Rows(2).Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth225pt
.Color = wdColorBlack
End With
End If
End Sub

Private Sub CheckBox3_Click()
CheckBox3.Font.Bold = CheckBox2.Value
If CheckBox3.Value = False Then
CheckBox3.Font.Size = 10
ActiveDocument.Tables(1).Rows(1).Range.Font.Hidden = False
With ActiveDocument.Tables(1).Rows(2).Borders(wdBorderTop)
.LineStyle = wdLineStyleDot
.LineWidth = wdLineWidth025pt
.Color = wdColorGray25
End With
Else
CheckBox3.Font.Size = 12
ActiveDocument.Tables(1).Rows(1).Range.Font.Hidden = True
With ActiveDocument.Tables(1).Rows(2).Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth225pt
.Color = wdColorBlack
End With
End If
End Sub

Private Sub CheckBox4_Click()
CheckBox4.Font.Bold = CheckBox2.Value
If CheckBox4.Value = False Then
CheckBox4.Font.Size = 10
ActiveDocument.Tables(1).Rows(1).Range.Font.Hidden = False
With ActiveDocument.Tables(1).Rows(2).Borders(wdBorderTop)
.LineStyle = wdLineStyleDot
.LineWidth = wdLineWidth025pt
.Color = wdColorGray25
End With
Else
CheckBox4.Font.Size = 12
ActiveDocument.Tables(1).Rows(1).Range.Font.Hidden = True
With ActiveDocument.Tables(1).Rows(2).Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth225pt
.Color = wdColorBlack
End With
End If
End Sub

Private Sub CheckBox5_Click()
CheckBox5.Font.Bold = CheckBox2.Value
If CheckBox5.Value = False Then
CheckBox5.Font.Size = 10
ActiveDocument.Tables(1).Rows(1).Range.Font.Hidden = False
With ActiveDocument.Tables(1).Rows(2).Borders(wdBorderTop)
.LineStyle = wdLineStyleDot
.LineWidth = wdLineWidth025pt
.Color = wdColorGray25
End With
Else
CheckBox5.Font.Size = 12
ActiveDocument.Tables(1).Rows(1).Range.Font.Hidden = True
With ActiveDocument.Tables(1).Rows(2).Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth225pt
.Color = wdColorBlack
End With
End If
End Sub
 
D

Doug Robbins - Word MVP

I do not see anywhere in your code where the document is being saved after
making the changes, so it's likely that it is something other than the code
that you have included that is causing the behaviour.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

Bear

Newt and Doug:

Word 2000 in XP Pro SP2

If you select an entire row, including the row-ending marker, and set it all
to any style other than Normal, eventually that row-ending marker will be set
back to Normal.

So if you hide a row by applying a style defined as hidden, eventually the
last marker will lose that style and the row will appear again. HOWEVER the
C++ in Word notices when an entire row except the last marker is hidden, and
considers the entire row hidden.

So your answer may be in hiding the range less the end-of-row marker.

Not sure, just a thought.

Bear
 

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