• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1920
  • Last Modified:

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

0
arthrex
Asked:
arthrex
1 Solution
 
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
 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now