背景:专有的兽医软件会生成一个文档,该文档预先填充了包含特定患者数据的合并字段。我感兴趣的领域是重量,但它是一个看起来像“24.5 kg”的字符串(Top_Stat)。
我创建了一个脚本来读取该字段并将其转换为整数。但是我现在想使用这个整数来计算基于动物体重的男性药物剂量。为此创建文档变量,但变量(名称和值)存储在文档中。我至少希望删除该值,但似乎无法使用以下脚本获得结果。
Sub GetWeight()
ActiveDocument.Variables("WeightInKg").Delete
WeightInt = ActiveDocument.MailMerge.DataSource.DataFields("Top_Stat").Value
WeightInt = Replace(WeightInt, " kg", "") 'This removes the superfluous text
WeightInt = Val(WeightInt) 'This converts the weight into a number (integer)
ActiveDocument.Variables.Add Name:="WeightInKg", Value:=WeightInt 'Add the Word variable
ActiveDocument.Fields.Update
End Sub
我错过了什么?抱歉,我是 VBA 新手。