+ Reply to Thread
Results 1 to 8 of 8

Content Control Checkbox Hide and Show Text

  1. #1
    Registered User
    Join Date
    05-08-2013
    Location
    Monterey, California
    MS-Off Ver
    Excel 2007
    Posts
    40

    Content Control Checkbox Hide and Show Text

    I want to use a content control checkbox in a MS Word 2010 document to hide or show some bookmarked text. There are a number of checkboxes in the document that I have - each one when clicked I would like to trigger an action of expanding or collapsing some text. Any ideas?

    Thank you!!!!

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Content Control Checkbox Hide and Show Text

    Anything you do to show/hide content by toggling the font properties is unreliable in a corporate environment. That's because whether text formatted as hidden actually displays or prints has little to do with that property. Rather, it all depends on how the user has Word configured. Depending on that configuration, text formatted as hidden may:
    • neither display nor print
    • display but not print
    • print but not display
    • both display and print

    Although it's probably safe to programmatically turn off the hidden-text printing, users may not appreciate you fiddling with its display, since toggling it off also toggles off the display of other formatting, such as spaces, tabs & paragraph breaks.

    If you really want to control what happens, you need to conditionally insert/delete the content. To do that, try:
    Please Login or Register  to view this content.
    There are two issues with this approach:
    1. Bookmarks are all too easily deleted by ham-fisted users, breaking the process; and
    2. Doing anything more than simple text output requires considerably more coding.

    An alternative approach, which would allow the content to remain in the document would be to use Custom Document Properties and field coding. This is easier for users to maintain and simplifies anything you might want to do that entails formatting:
    Please Login or Register  to view this content.
    With this approach, you don't need any bookmarks and the same Custom Document Property can be used to update multiple locations in the document - all you need is a field coded along the lines of the following for each:
    {IF{DOCPROPERTY Chk1}= 1 "True Text"} or:
    {IF{DOCPROPERTY Chk1}= 1 "True Text" "False Text"}
    where field brace pairs (i.e. '{ }') are created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. The output can contain pictures and tables as well as text. You create the Custom Document Properties via File|Properties|Advanced Properties>Custom. With this approach, the content remains in the document and is readily accessible by pressing Alt-F9 to reveal the field contents. It's still possible to show & print the field codes instead of their values but, since few users want to do either, the macro can fairly safely turn both of those options off.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    05-08-2013
    Location
    Monterey, California
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Content Control Checkbox Hide and Show Text

    Paul - first off Thank you! I appreciate you taking the time to respond.

    I do have another couple of questions:

    What is the difference between these two?
    {IF{DOCPROPERTY Chk1}= 1 "True Text"} or:
    {IF{DOCPROPERTY Chk1}= 1 "True Text" "False Text"}

    Also, I presume "True Text" is the text that I want to toggle on (visible) or off (not visible). I highlight this in the document, push ctrl-F9 (to get brackets), which results in:

    {"True Text"}

    The part I don't understand is: IF{DOCPROPERTY Chk1}= 1. All I want visible to the users is the Text, and when I attempt to do the above see "IF{DOCPROPERTY Chk1}= 1" in the document. Also what if Chk1 = 0 (box is unchecked)? Thanks.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Content Control Checkbox Hide and Show Text

    Quote Originally Posted by schmidt1962 View Post
    Paul - first off Thank you! I appreciate you taking the time to respond.

    I do have another couple of questions:

    What is the difference between these two?
    {IF{DOCPROPERTY Chk1}= 1 "True Text"} or:
    {IF{DOCPROPERTY Chk1}= 1 "True Text" "False Text"}
    The difference is that the second version has a 'false' result as well as the 'true' result. IF fields in Word don't need the explicit inclusion of a 'false' response.
    Also, I presume "True Text" is the text that I want to toggle on (visible) or off (not visible). I highlight this in the document, push ctrl-F9 (to get brackets), which results in:

    {"True Text"}
    You shouldn't be seeing any braces or quote marks, just the text between them. You can't just type the fields or copy/paste the code from here into your document. All the field braces (i.e. { }) have to be created in the document itself via Ctrl-F9 or via Insert|Quick Parts|Field. Ctrl-F9 is far simpler, though. If you need to see & edit the field codes, pressing Alt-F9 will toggle their display on/off.
    The part I don't understand is: IF{DOCPROPERTY Chk1}= 1. All I want visible to the users is the Text, and when I attempt to do the above see "IF{DOCPROPERTY Chk1}= 1" in the document. Also what if Chk1 = 0 (box is unchecked)? Thanks.
    Once created properly, the fields should behave as described.

  5. #5
    Registered User
    Join Date
    05-08-2013
    Location
    Monterey, California
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Content Control Checkbox Hide and Show Text

    Hide or Unhide Text.docm

    Paul, I still can't get it to work. I know there must be something I am missing that is totally obvious due to my lack of experience with Word programming. The only way I think I can resolve this problem is by attaching a word document to show you.

    I created the "{}" using Ctrl-F9, and have attempted to follow your example to the letter. I created a custom control for Chk1. The checkbox title is "Button1". When I click it I get "Error! Unknown op code for conditional." The only way to bring the text back up is with Alt-F9 (instead of what I want which is unclicking the button to bring it back), but this shows any users the "IF{DOCPROPERTY Chk1}=1", something I don't want them to see.

    Appreciate your help - Thanks, Eric

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Content Control Checkbox Hide and Show Text

    Without wanting to place too fine a point on it, none of your output text is enclosed within the required double quotes as indicated in the two examples I've given you. You also don't have the required space after the '=' sign. Furthermore, whereas I've specified a custom document property using 1 or 0, you've used one with 'Yes' or 'No'. A field that's looking for a 1 will treat both 'Yes' and 'No' as not 1.
    Last edited by macropod; 10-29-2014 at 12:01 AM.

  7. #7
    Registered User
    Join Date
    05-08-2013
    Location
    Monterey, California
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Content Control Checkbox Hide and Show Text

    Paul - my apologies for my ignorance.. I had seen a previous post that you had and misunderstood that the quotes were necessary.. Thank you!

    I have managed to get it to work, though had some difficulties with numbering within the text turning off when I did the ctrl-F9 to get the {}. I fixed that part, but now what is strange is I had to revise your code up above so it works:

    Please Login or Register  to view this content.

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Content Control Checkbox Hide and Show Text

    Quote Originally Posted by schmidt1962 View Post
    now what is strange is I had to revise your code up above so it works
    That suggests only that you had the true & false conditions in the field code switched around. Regardless, it's of no consequence.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Show and Hide a section of cells w a Checkbox Macro
    By Attrition in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2014, 12:59 PM
  2. Checkbox to show / hide workbook sheets
    By ed_b1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-09-2013, 07:17 AM
  3. Show/Hide Checkbox
    By kalyanverma in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-12-2011, 01:33 PM
  4. Show/Hide columns by checkbox and cell text
    By ksmoore in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-09-2010, 02:20 PM
  5. Use checkbox to show/hide sheets?
    By Zheno in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-03-2010, 02:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1