Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 禁用文本输入对象_Vba_Ms Word_Textinput_Disabled Input - Fatal编程技术网

Vba 禁用文本输入对象

Vba 禁用文本输入对象,vba,ms-word,textinput,disabled-input,Vba,Ms Word,Textinput,Disabled Input,我有一个复选框,如果复选框.Value=False我想禁用我的TextInput对象。在互联网上有一些建议,但所使用的方法对我不起作用,因为没有找到这些方法 我用.Valid-方法进行了尝试: Dim tf As TextInput Dim checkbox As CheckBox Sub checkbox_click() Set checkbox = ActiveDocument.FormFields("checkbox").CheckBox Set tf = Acti

我有一个
复选框
,如果
复选框.Value=False
我想禁用我的TextInput对象。在互联网上有一些建议,但所使用的方法对我不起作用,因为没有找到这些方法

我用
.Valid
-方法进行了尝试:

Dim tf As TextInput
Dim checkbox As CheckBox

Sub checkbox_click()

Set checkbox = ActiveDocument.FormFields("checkbox").CheckBox
Set tf = ActiveDocument.FormFields("textfield").TextInput

If checkbox.Value = False

    tf.Valid = False
End If

End Sub

但由于某些原因,这不起作用。我在internet上找到了
tf.Enabled=False
,但这种方法在我的情况下是未知的。

虽然internet可以提供帮助,但您也应该在使用帮助的同时使用VBE中的对象浏览器。花5秒钟搜索FormField会给你答案

Dim tf As TextInput
Dim checkbox As CheckBox

Sub checkbox_click()

Set checkbox = ActiveDocument.FormFields("checkbox").CheckBox

If checkbox.Value = False
    ActiveDocument.FormFields("textfield").Enabled = False
End If

End Sub

你需要更像这样的东西:

Dim ff As FormField
Dim checkbox As CheckBox
.
.
Set checkbox = ActiveDocument.FormFields("checkbox").CheckBox
Set ff = ActiveDocument.FormFields("textfield")

If checkbox.Value = False
  ff.Enabled = False
End If
对于旧版FormField对象,您需要的某些属性与FormField本身关联,而其他属性则与FormField的子对象关联,如FormField.Checkbox

因此,这里的问题是
tf
FormField.TextInput
对象,而
.Enabled
FormField
对象的属性

与您的问题无关,但作为观察,FormFields没有与VBA事件正常意义上的单词事件关联。每个字段的设置告诉Word在“进入”和/或“退出”时运行命名子项,就是这样。没有实际的点击事件。使用使这些事情看起来像事件的名称没有问题,但我只是想提一下