none
Show/Hide table in Word 2007

    Question

  • I am trying to figure out how to hide a table based on a certain condition. It seems tables do not have an identifier nor are based on a object and have no "visible" property. How can I Show/hide objects in a VSTO based Word template?

    Ken

    Friday, April 15, 2011 4:49 PM

Answers

  • Hi Ken,

    Be warned that setting the font to hidden prevents neither the viewing nor the printing of the table and its contents. For someone to view a hidden table's contents, a simple click on the ¶ on the ribbon/toolbar is the most it takes. And, if the use has checked Word's option to display hidden text, even that is unnecessary. For printing, it's as simple as having Word's option to print hidden text activated. Since these a Word settings rather than document settings, it's difficult to control, even with code.


    Cheers
    Paul Edstein
    [MS MVP - Word]
    • Marked as answer by Bruce Song Tuesday, April 26, 2011 6:38 AM
    Saturday, April 16, 2011 3:54 AM
  • Hi Paul,

    You are right, but it's normaly no problem. We have been using this solution for many years and nearly never any problems. In documents where we use this solution we make the document/Word setting as they should be to not show/print hidden text. So the possiblility to show and print hidden text has never been any problem for us, but there is one thing you really need to think about when using the hidden text attribute. If you have created a form with formfields and have checkboxes controlling hidden/visible parts of the document dynamicly, hiding a part of the document doesn't prevent the user from entering the formfields in the hidden section. For the user it looks like he can no longer edit the document as no visible formfield is selected, so if you hide a section with formfileds, the formfields must be disabled so the user can't enter them with Tab/Shit-Tab.

    Regards,
    Lars-Eric

    • Marked as answer by Bruce Song Tuesday, April 26, 2011 6:39 AM
    Saturday, April 16, 2011 8:26 AM

All replies

  • Hello,

    The following VBA code will hide/show the first table in the document. I hope it helps.

        With ActiveDocument.Tables(1).Range.Font
            .Hidden = Not .Hidden
        End With

    Regards,
    Lars-Eric

    • Proposed as answer by Micha Häsler Tuesday, August 12, 2014 12:28 PM
    Friday, April 15, 2011 5:01 PM
  • Thanks! Worked perfectly?

     

    Ken

    Friday, April 15, 2011 5:15 PM
  • Hi Ken,

    Be warned that setting the font to hidden prevents neither the viewing nor the printing of the table and its contents. For someone to view a hidden table's contents, a simple click on the ¶ on the ribbon/toolbar is the most it takes. And, if the use has checked Word's option to display hidden text, even that is unnecessary. For printing, it's as simple as having Word's option to print hidden text activated. Since these a Word settings rather than document settings, it's difficult to control, even with code.


    Cheers
    Paul Edstein
    [MS MVP - Word]
    • Marked as answer by Bruce Song Tuesday, April 26, 2011 6:38 AM
    Saturday, April 16, 2011 3:54 AM
  • Hi Paul,

    You are right, but it's normaly no problem. We have been using this solution for many years and nearly never any problems. In documents where we use this solution we make the document/Word setting as they should be to not show/print hidden text. So the possiblility to show and print hidden text has never been any problem for us, but there is one thing you really need to think about when using the hidden text attribute. If you have created a form with formfields and have checkboxes controlling hidden/visible parts of the document dynamicly, hiding a part of the document doesn't prevent the user from entering the formfields in the hidden section. For the user it looks like he can no longer edit the document as no visible formfield is selected, so if you hide a section with formfileds, the formfields must be disabled so the user can't enter them with Tab/Shit-Tab.

    Regards,
    Lars-Eric

    • Marked as answer by Bruce Song Tuesday, April 26, 2011 6:39 AM
    Saturday, April 16, 2011 8:26 AM
  • Hi Paul,

    Have you resolved your problem yet and do the suggestions help you?

    If you still have any concern on the thread, feel free to follow up. 

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 21, 2011 3:41 AM