View Single Post
 
Old 11-14-2023, 06:04 PM
TheOstrich TheOstrich is offline Windows 10 Office 2021
Novice
 
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