[如需转载,请在转载时注明出处,并保证本文的完整性]
用Excel做测试用例的数据模板,复杂的模板,如果手动来填写预期结果,非常麻烦,一则容易出错,二则需要重复计算浪费时间。那么如果不是很复杂的逻辑运算完全用Excel公式可以实现,不过比较复杂的还是用宏来实现比较好。
G9%HT_ZCP~{88(1IY.jpg)
G9%HT_ZCP~{88(1IY.jpg)

那么实现用Excel中的按钮调用宏分三步:
1. 创建宏:以Excel 2003为例,工具——宏——录制新宏,弹出对话框:
G9%HT_ZCP~{88(1IY.jpg)
G9%HT_ZCP~{88(1IY.jpg)
G9%HT_ZCP~{88(1IY.jpg)
G9%HT_ZCP~{88(1IY.jpg)

输入宏的名称“NewTest”,确定,新建成功。
2.编辑宏:打开VBA编辑器 工具——宏——宏,弹出窗体:

点击【编辑】,进入VBA编辑器中,假设编写一个宏实现以下功能:
以下Excel中,ODC部门的工作年限5年以上涨工资20%,工作年限5年以下涨工资15%,其他部门不调薪。求最 终调薪后结果列表。
基础数据:

期望结果:

那么就通过编写宏来实现以上计算:
3.创建按钮并指定宏:插入——图片——自选图形,如:
选择按钮然后,右键,指定宏,选择刚创建的宏NewTest,然后便可单击按钮,便可执行宏,自动计算出调整后的薪资,并填写到Expect_Result表中。
注意:为了保证宏可以正常执行,要在工具——宏——安全性,安全级别调整为最低的。