Word 2007 VBA trigger visibility of table

Hi experts,

in Word 2007 we want to have a checkbox which triggers the visibility of a table. The way we implemented that was using a bookmark that contains the table  and we hide the font of the bookmark.
The problem is when a client has the paragraph marks turned on, the table is always visible.

Do you guys have a better way to accomplish this task?

Thanks
If CheckBox_PS.Value = False Then
    ActiveDocument.Bookmarks("Table_PS").Range.Font.Hidden = True
Else
    ActiveDocument.Bookmarks("Table_PS").Range.Font.Hidden = False
End If

Open in new window

arthrexAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

irudykCommented:
By design the Show/Hide function displays/hides all non-visible items (e.g. hidden text).  Because a user can click on this option at any time, one option would be to reprogram what that function does.  Although, doing so won't stop a user from going into the Word Options and setting the display properties to what they want (thus circumventing any reprogramming that you might do).
Another option I can think of is to not only to toggle the font's hidden property, but to also set the table row height and border color properties. If you set the row height to 0.01" and the border color properties to a white color (i.e. when you set the font's hidden property on) then the user won't easily see the contents of the table when they click the Show/Hide button.
The following revised code will do this:

If CheckBox_PS.Value = False Then
    With ActiveDocument.Bookmarks("Table_PS").Range
        .Font.Hidden = True
        With .Tables(1)
            .Borders.InsideColor = wdColorWhite
            .Borders.OutsideColor = wdColorWhite
            .Rows.Height = 1
            .Rows.HeightRule = wdRowHeightExactly
        End With
    End With
Else
    With ActiveDocument.Bookmarks("Table_PS").Range
        .Font.Hidden = False
        With .Tables(1)
            .Borders.InsideColor = wdColorAutomatic
            .Borders.OutsideColor = wdColorAutomatic
            .Rows.HeightRule = wdRowHeightAuto
        End With
    End With
End If
Application.ScreenRefresh

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PandaPantsCommented:
I'm not sure of your purpose in hiding the table, so this may be wildly off base. However, if the data in the table is static and you just want to keep it out of the way until the user wanted to look at it (i.e., the issue is convenience and layout, not security), then you could store the table in an AutoText entry (called, e.g., "Show_Table_PS"), and place the checkbox control next to a bookmark that will either be empty or will contain the table, depending on the status of the checkbox.

The following revised code might do this:
If CheckBox_PS.Value = False Then
    ActiveDocument.Bookmarks("Table_PS").Range.Delete
Else
    ActiveDocument.Bookmarks("Table_PS").Range.Select
    With Selection
        ' First, the name of the AutoText entry is typed directly into the document:
            .TypeText Text:="Show_Table_PS"
        ' Second, the user presses "F3":
            .Range.InsertAutoText
    End With ' Selection
End If

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.