如何根据所选的下拉值打印价格?

How do I print a price depending on the dropdown value that is selected?

我有这个 table 和以下 headers:产品、数量、Price/Kg、总计

“产品”列中的单元格都是包含公司提供的产品的下拉列表,“Price/Kg”是 TextInputs。

我想根据下拉菜单的值将指定价格打印到 TextInput。

我有这个子程序,但它什么也没做:

Sub getPreco()

Select Case ActiveDocument.FormFields("produtos").DropDown.Value
    Case "Amêijoas Vietnamitas"
        ActiveDocument.FormFields("TextBox1").TextInput.Result = "1 euro"
    Case "Gambas"
        ActiveDocument.FormFields("TextBox1").TextInput.Result = "2 euros"
    Case Else
        ActiveDocument.FormFields("TextBox1").TextInput.Clear
        MsgBox "Price not yet defined"

End Select
End Sub
Sub getPreco()

Select Case ActiveDocument.FormFields("produtos").DropDown.Value
    Case 1
        ActiveDocument.FormFields("Texto1").Result = "1 euro"
    Case 2
        ActiveDocument.FormFields("Texto1").Result = "2 euros"
    Case Else
        ActiveDocument.FormFields("Texto1").TextInput.Clear
        MsgBox "Preco ainda nao definido"

End Select
End Sub

您不需要任何 VBA。您需要做的就是检查下拉表单字段的 'Calculate on Exit' 属性 并使用按以下行编码的公式字段:

{IF{REF produtos}= "Amêijoas Vietnamitas" "€1" {IF{REF produtos}= "Gambas" "€2" "Preco ainda nao definido"}}

注意: 上述示例的字段大括号对(即“{ }”)都是在文档本身中创建的,通过 Ctrl-F9(Cmd-F9 在Mac 或者,如果您使用的是笔记本电脑,则可能需要使用 Ctrl-Fn-F9);您不能简单地键入它们或从该消息中复制并粘贴它们。通过任何标准的 Word 对话框添加它们也不切实际。字段结构中表示的空格都是必填项。