VBA:处理PowerPivot刷新错误

我使用macros来刷新PowerPivot中的一些数据,然后在我的计算机上自动保存更新的文件。 我的问题是,我正在使用SSH连接到数据库,由于连接不良,有时会崩溃,并停止刷新过程。 然后powerpivot无法刷新工作表,但我的macros继续执行,如果没有发生…

我想知道是否有办法在VBA中处理这样的错误,以便循环刷新过程,直到完全正确执行。

我build议的最简单和最直接的方法是使用布尔variables,如果powerPivot正确刷新,则将其赋值为yes;如果powerPivot没有正确刷新,则返回false。 因此只有当variables为真时macros才会运行。 一个例子是:

Dim result As Boolean result = False if PowerPivot gets refreshed then 'the refesh code result = true end if if result = true then 'run the macro code end if 

因此只有当powerpivot被完全刷新时,macros才会运行。 否则不是。