Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 11-24-2022, 06:29 AM
macropod's Avatar
macropod macropod is offline VBA content control to display/hide a section of text Windows 10 VBA content control to display/hide a section of text Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The following macro assumes you're using a Checkbox Content Control titled 'Checkbox1' and, for the text to be shown/hidden, a Rich Text Content Control titled 'ConditionalText':
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
With CCtrl
  Select Case .Title
    Case "Checkbox1"
      ActiveDocument.SelectContentControlsByTitle("ConditionalText")(1).Range.Font.Hidden = Not .Checked
  End Select
End With
End Sub
The code goes in the 'ThisDocument' code module of the document or its template.

With the checkbox checked, the content will be formatted as visible; unchecked, hidden. To reverse the options, delete the 'Not' from the code.

Do note that whether text formatted as hidden will remain visible - or even be printed if not visible - depends on how the user has their Word installation configured.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA content control to display/hide a section of text How to Display Text on Multiple dropdown content control result philip.anthony Word VBA 11 03-28-2022 02:15 PM
VBA content control to display/hide a section of text Content Control values NOT display name silverspr Word VBA 9 09-30-2020 07:53 AM
How to display tag in Content Control instead of title vinbalraj Word 1 03-02-2018 08:55 AM
VBA content control to display/hide a section of text How to manage (display/hide) parts of the text within a document via table of content Curby Word 2 06-30-2016 12:29 AM
Help with show/hide content control acontreras Word VBA 0 10-21-2014 07:28 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft