[英]MS Word VBA for formfields
I am trying to assign a numeric value in VBA for a dropdown formfield. 我试图在VBA中为下拉表单字段分配一个数值。 I have the Msgbox just to test functionality: 我有Msgbox只是为了测试功能:
Sub ScreenB()
Dim a As Double
If ActiveDocument.FormFields("Dropdown9").DropDown.Value = No Then
a = 1
Else
a = 2
End If
MsgBox a
End Sub
With this code, my Msgbox does not change (it reads "2"), even when I change the the dropdown from Yes to No, or vice-versa. 使用此代码,即使我将下拉列表从“是”更改为“否”,我的Msgbox也不会更改(读取为“ 2”),反之亦然。 I also tried putting quotes around yes ("Yes") in the VBA code and got a Type Mismatch error. 我还尝试在VBA代码中用双引号将“是”(“是”)括起来,并收到类型不匹配错误。
You should use FormFields.Result 您应该使用FormFields.Result
Sub ScreenB()
Dim a As Double
If ActiveDocument.FormFields("Dropdown9").Result = "No" Then
a = 1
Else
a = 2
End If
MsgBox a
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.