复选框以修改Word 2010中的文本框 [英] Checkbox to modify textbox in Word 2010
问题描述
我想拥有一个MS Word 2010文档,其中有一个复选框(可插入)和一个文本框(文本字段),根据是否单击该复选框,它们会显示不同的文本.
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...
我认为该解决方案应在Visual Basic中使用?
I would think that the solution should be used in Visual Basic?
推荐答案
像这样吗?
Private Sub CheckBox1_Change()
If CheckBox1.Value = True Then
TextBox1.Text = "Checked!"
Else
TextBox1.Text = "Unchecked."
End If
End Sub
这假设您有一个名为CheckBox1
的复选框和一个名为TextBox1
的文本框.上面的代码在ThisDocument模块中.
This assumes you have a checkbox called CheckBox1
and a text box called TextBox1
. The above code goes in the ThisDocument module.
结果如下所示:和此.
编辑糟糕,我在Excel中制作了这些图片...哦,它们在Word中看起来几乎相同.
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
这篇关于复选框以修改Word 2010中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!