【发布时间】:2011-04-12 19:40:37
【问题描述】:
运行以下代码时,我收到“对象变量或未设置块变量”错误消息。它在 Access 中,指的是 Excel 电子表格。代码有什么问题?
wsTest.Range("A11").Activate
Do Until IsEmpty(ActiveCell)
intX = intX + wsTest.Cells(ActiveCell.Row, "L") 'error occurs on this line
intY = intY + wsTest.Cells(ActiveCell.Row, "I")
ActiveCell.Offset(1, 0).Select ' Step down 1 row to the next cell.
Loop
第一次运行代码,没有错误,只有第二次。关闭并重新打开 Access “修复”了该问题。这怎么可能和这段代码有关?
【问题讨论】:
-
错误出现在哪一行?
-
我用该信息更新了上面的代码。
-
ActiveCell 指的是一个 Excel 对象,因此您可能应该使用您的 XL 应用程序引用来限定它。例如:xlApp.Activecell