使用 IE 的 Excel vba 中出现间歇性 VBA 运行时错误 91



当excel VBA代码将值传递给IEobject时,我间歇性地面临运行时Error 91。假设一组 15 次迭代,我在同一个地方遇到 3-4 次错误.

当我手动(F8)运行它时,看不到错误。我增加了延迟,但徒劳无功。

Acct_name字段将保持灰色,直到输入货币。IE.document.frames("company").document.forms("account").document.all("currency") .值="美元" IE.document.frames("company").document.forms("account").document.all("currency") .fireevent("onblur")

。延迟在这里

在IE.document.frames("company").document.forms("account").document.all时做。("acct_name")。就绪状态<>"完成"'间歇性运行时错误 91 圈

IE.document.frames("company").document.forms("account").document.all("acct_name" )。值 = "abc" '间歇运行时错误 91

正如 Tim 所建议的,它的时序问题您可以添加 5 秒的延迟并查看输出。

   load:
Do While IE.readystate <> 4: DoEvents: Loop
Application.Wait Now() + TimeSerial(0, 0, 5) ' delay of 5 seconds
Set account = IE.document.getElementById("account_name")
If account Is Nothing Then GoTo load
account.Value = "abc"

最新更新