Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-14-2023, 04:32 PM
TheOstrich TheOstrich is offline Hiding rich text content control using checkbox - Removing extra spacing Windows 10 Hiding rich text content control using checkbox - Removing extra spacing Office 2021
Novice
Hiding rich text content control using checkbox - Removing extra spacing
 
Join Date: Nov 2023
Posts: 3
TheOstrich is on a distinguished road
Default Hiding rich text content control using checkbox - Removing extra spacing

Hi all,



I have a check box content control which I'm using to show/hide a rich text content control containing multiple paragraphs of text.

Everything works great, except I have one issue — the rich text content control "container" is still visible, which produces an extra line/paragraph in my document that I do not want.

For example, here is what it looks like:

Image.png

and here is what I want it to look like:

Image2.png

Below is a snippet of the code I'm using to (1) determine the status of the checkbox, and (2) hide the content control.

Code:
isChecked = ActiveDocument.SelectContentControlsByTitle("Checkbox")(1).Checked
ActiveDocument.SelectContentControlsByTitle("Content Control")(1).Range.Font.Hidden = Not isChecked
I've also attached a simplified version of the Word file to illustrate this issue.

Is there any way I can get rid of this extra line? I tried bookmarking the content control and hiding it that way, as well as playing around with the paragraph settings, but no luck. Thank you!
Attached Files
File Type: docm Example CC Issue.docm (69.3 KB, 9 views)
Reply With Quote
  #2  
Old 11-14-2023, 05:07 PM
Guessed's Avatar
Guessed Guessed is offline Hiding rich text content control using checkbox - Removing extra spacing Windows 10 Hiding rich text content control using checkbox - Removing extra spacing Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Have you looked at whether the content control includes the final paragraph mark or not?

If the content control sits in front of a paragraph mark then the macro to hide the content control range ONLY won't impact the visibility of that paragraph mark. So have your macro also hide that element of the document or set its height to 1pt.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 11-14-2023, 06:04 PM
TheOstrich TheOstrich is offline Hiding rich text content control using checkbox - Removing extra spacing Windows 10 Hiding rich text content control using checkbox - Removing extra spacing Office 2021
Novice
Hiding rich text content control using checkbox - Removing extra spacing
 
Join Date: Nov 2023
Posts: 3
TheOstrich is on a distinguished road
Default

Thanks for the reply and suggestions! I had the paragraphs written and then basically highlighted all of them and put them inside the rich text content control after the fact, rather than establishing the rich text content control first and then entering the content.

All that to say the content control likely sits in front of the paragraph mark (which may be my issue), though I'm not sure. See screenshot below if you can tell from that.

Screenshot.png

Any ideas how I would go about modifying the macro to hide that element of the document, especially considering the content control may contain a variable number of paragraphs? Would I create a loop?

I tried the following code and it hides a few of the paragraphs (including the last paragraph in the document outside of the content control, which should not be hidden) before producing a runtime error.

Code:
Sub HideText()
    Dim isChecked As Boolean, cc As ContentControl, i As Integer
    
    'Get the state of the checkbox
    isChecked = ActiveDocument.SelectContentControlsByTitle("Checkbox")(1).Checked
        
    'Toggle the visibility of the content control
    Set cc = ActiveDocument.SelectContentControlsByTitle("ContentControl")(1)

    If cc.Title = "ContentControl" Then
        For i = 1 To cc.Range.Paragraphs.Count
            cc.Range.Paragraphs(i).Range.Font.Hidden = Not isChecked
        Next i
    End If
    
End Sub
For the second suggestion, is it possible to customize the height of a content control? I tried changing the font size to 1pt but that didn't seem to change the size of the content control container that is not beeing hidden.
Reply With Quote
  #4  
Old 11-14-2023, 07:23 PM
Guessed's Avatar
Guessed Guessed is offline Hiding rich text content control using checkbox - Removing extra spacing Windows 10 Hiding rich text content control using checkbox - Removing extra spacing Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Try this code. Put it into the ThisDocument Module to have it run automatically when you exit any content control.
Code:
Private Sub Document_ContentControlOnExit(ByVal myCC As ContentControl, Cancel As Boolean)
  Dim aCC As ContentControl
  If myCC.Title = "Checkbox" Then
    For Each aCC In ActiveDocument.SelectContentControlsByTitle("ContentControl")
      aCC.Range.Font.Hidden = Not myCC.Checked
      aCC.Range.Paragraphs.Last.Range.Font.Hidden = Not myCC.Checked
    Next aCC
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 11-15-2023, 11:58 AM
TheOstrich TheOstrich is offline Hiding rich text content control using checkbox - Removing extra spacing Windows 10 Hiding rich text content control using checkbox - Removing extra spacing Office 2021
Novice
Hiding rich text content control using checkbox - Removing extra spacing
 
Join Date: Nov 2023
Posts: 3
TheOstrich is on a distinguished road
Default

Thank you! That worked except the code is also hiding the first paragraph outside of the content control for some reason. I can get around this by just inserting an extra blank paragraph at the bottom of the content control, which seems to fix the issue. Appreciate your help!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding rich text content control using checkbox - Removing extra spacing Rich text Content Control Duplicate or Alternative BarnabyS Word 11 10-08-2020 12:06 PM
Copy Formatted Text in one Rich Text Content Control to another Rich Text Content Control Haygordon Word 1 04-05-2019 05:43 AM
Hiding rich text content control using checkbox - Removing extra spacing Replicate rich text content control value at top of each page gebobs Word 5 05-16-2018 06:00 AM
Hiding rich text content control using checkbox - Removing extra spacing How do you set rich text in a content control Testor Word VBA 4 07-08-2012 07:55 AM
Hiding rich text content control using checkbox - Removing extra spacing Rich Text Content Control - Allow User Formatting keithacochrane Word 1 05-28-2012 05:06 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:54 AM.


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