简体   繁体   中英

MS Word VBA for formfields

I am trying to assign a numeric value in VBA for a dropdown formfield. I have the Msgbox just to test functionality:

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. I also tried putting quotes around yes ("Yes") in the VBA code and got a Type Mismatch error.

You should use 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM