Checkbox to modify textbox in Word 2010

天大地大妈咪最大 提交于 2019-12-11 06:57:08

问题


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

and 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!