Here's my code
Sub HideText1BasedOnDropdown1()
Dim dropdownValue As String
Dim textFormField As FormField
' Get the value of the Drop-Down Form Field with the bookmark "Dropdown1"
dropdownValue = ActiveDocument.FormFields("Dropdown1").Result
' Check the value of the Drop-Down Form Field and hide or show the Text Form Field accordingly
If dropdownValue = "Yes" Then
ActiveDocument.ContentControls(Text1).Hidden = True
Else
ActiveDocument.ContentControls(Text1).Hidden = False
End If
End Sub
The bug highlight's that first ".Hidden" and says:
Compile error: Method or data member not found
I'd rather be using a modern content control drop down box but I read it needs to be a legacy version so I can run my macro on exiting from it.
I think the crux of the problem is signaling the identity of the text box that needs to be hidden. I've also tried to hide a legacy text form field rather than Content Control box with this code, but get essentially the same result:
If dropdownValue = "Yes" Then
ActiveDocument.FormFields("Text1").Hidden = True
Else
ActiveDocument.FormFields("Text1").Hidden = False
There are two errors:
ActiveDocument.SelectContentControlsByTag("Text1")(1).Range.Font.Hidden = TrueThis would work if you have at least one CC with a tag "Text1".