当excel中有事件时,vbs不会执行所有的代码行

我有一个脚本新手问题。 试图寻找答案,但无法find答案。 或者不能够制定足够的search引擎来理解。 我试图从VBS控制excel。 我在VBS中写了简单的脚本。 当Excel中没有事件时,脚本可以正常运行。 但是当我多次按下鼠标button时,VBS脚本不会执行FOR循环中的所有代码行(只有第一个被执行,我的代码示例:

dim FileName dim firstCell dim run_time dim xlBook dim i FileName = "excelTaimeris.xlsx" on error resume next Set objExcel = GetObject(, "Excel.Application") if err.number = 0 then Set xlBook = objExcel.Application.ActiveWorkBook if xlBook.Name = FileName then objExcel.DisplayAlerts = true objExcel.Visible =true Set firstCell = xlBook.ActiveSheet.range("A2") 'nustatom pirmaji laukeli automatiniam ejimui zemyn 'doEvents for i=0 to 10 WScript.Sleep 1000 firstCell.offset(i-1,0).Interior.ColorIndex = 2 firstCell.offset(i, 0).Interior.ColorIndex = 44 next else msgbox "wrong excel is open" end if 

我相信这是与操作系统和Excel之间共享CPU的事情。 我应该实施某种方式来检查VBS脚本是否执行代码行。 如果没有,再次执行?

提前感谢您的时间!