问题
I want to have a MS Word 2010 document where there is a checkbox (ckeckable) and a textbox (textfield) where different text is displayed depending on whether the checkbox is clicked or not.
I have tried searching for it but somehow all the suggestions are not meant as solutions for the checkbox question...
I would think that the solution should be used in Visual Basic?
回答1:
Something like this?
Private Sub CheckBox1_Change()
If CheckBox1.Value = True Then
TextBox1.Text = "Checked!"
Else
TextBox1.Text = "Unchecked."
End If
End Sub
This assumes you have a checkbox called CheckBox1
and a text box called TextBox1
. The above code goes in the ThisDocument module.
Result looks like this


EDIT Whoops, I made these pics in Excel... Oh well, they look almost identical in Word.
EDIT You have now changed the requirement and want the textbox to "be hidden" when the checkbox is unchecked. There is no formal way to "hide" a textbox, but you can remove it visible features, i.e. the text it contains as well as the "sunken" special effect, such that it is indistinguishable from its background:
Private Sub CheckBox1_Change()
If CheckBox1.Value = True Then
TextBox1.Text = "Checked!"
TextBox1.SpecialEffect = fmSpecialEffectSunken
Else
TextBox1.Text = ""
TextBox1.SpecialEffect = fmSpecialEffectFlat
'Textbox is now "invisible"
End If
End Sub
来源:https://stackoverflow.com/questions/9224615/checkbox-to-modify-textbox-in-word-2010