我在 VBA 中为我们的 IBM iSeries / AS400 / 绿屏环境创建了一个宏,它在采购订单中查找项目编号,然后更改它们的价格并退出采购订单。在宏中是一个循环,用于解析采购订单的每一行,如果在第一页上找不到编号,则向下翻页到下一页。这是循环的代码:
'ItemNum and Price are entered by the user within Excel
Do Until IBMItemNum = ItemNum
If NumRow = 11 Then
'There are ten lines within purchase orders, after which one must page down
'to see the rest of the purchase order. This is where the problem occurs
autECLSession.autECLPS.SendKeys "[pagedn]"
NumRow = 1
End If
IBMItemNum = autECLSession.autECLPS.GetText(NumRow, 2, 5)
If IBMItemNum = ItemNum Then
autECLSession.autECLPS.SetCursorPos NumRow, 66
autECLSession.autECLPS.SendKeys Price
autECLSession.autECLPS.SendKeys "[field+]"
autECLSession.autECLPS.SendKeys "[enter]"
'After the item has been found and the price entered, the macro exits the PO
'Entering PageDown after the PO has been exited crashes the AS400 session
Exit Do
Else
'Check the next row
NumRow = NumRow + 1
End If
Loop
当且仅当我从循环中删除 PageDown SendKeys 命令时,此宏才能连续成功读取采购订单第一页上的每个数字。但是,即使 ItemNum 是 PO 上的第一个 IBMItemNum,宏也不会退出循环并会向下翻页(这也意味着循环已重复 10 次以上)。我的代码是否缺少退出条件的内容?