有没有一种方法可以在MS Word VBA中使用查找表?

时间:2018-12-05 19:06:19

标签: vba ms-word

我正在Word VBA中创建一个宏表单,该表单允许用户输入一个星期和一个权重值,该权重值将为他们计算百分位数。我是从一本看起来像这样的书的表格中构建表格的(抱歉,我不确定如何将表格添加到Stack Overflow问题中):

百分位数10th 50th 90th

第1周......... 3 .... 12 .... 34

第2周.... 5 .... 17 .... 39

Week3 ........ 8 .... 21 .... 42

当前,我的VBA代码如下:

If Week = 1 then
   If Weight < 3 then
   Selection.TypeText "less than 10th percentile for age"
   ElseIf Weight = 3 then
   Selection.TypeText "10th percentile for age"
   ElseIf Weight < 12 then
   Selection.TypeText "less than 50th percentile for age"
   ElseIf Weight = 12 then
   Selection.TypeText "50th percentile for age"
   ElseIf Weight < 34 then
   Selection.TypeText "less than 90th percentile for age"
   ElseIf Weight = 34 then
   Selection.TypeText "90th percentile for age"
   ElseIf Weight > 34 then
   Selection.TypeText "greater than 90th percentile for age"
   End If
ElseIf Week = 2 then
   If Weight < 5 then
   Selection.TypeText "less than 10th percentile for age"
...

该表实际上比3列和3行大得多,因此您可以想象这非常繁琐。该表本身对用户不可见,但在幕后编码。我想知道是否有一种方法可以向表中添加表,以便将来维护值更加简单,而不是像上面那样键入所有代码。谢谢!

我正在使用Word 2016。

0 个答案:

没有答案