简体   繁体   English

VBA:处理PowerPivot刷新错误

[英]VBA: Handling PowerPivot refreshing error

I'm using a Macro to refresh some data in PowerPivot, it then autosaves the updated file on my computer. 我正在使用宏刷新PowerPivot中的一些数据,然后将其自动保存在计算机上。 My problem is that I'm using SSH in order to connect to a database and due to bad connection sometimes it crashes and stop the refreshing process. 我的问题是我正在使用SSH来连接数据库,由于连接不良,有时会崩溃并停止刷新过程。 Then powerpivot can't refresh the worksheet but my macro keep being executed as if nothing happened... 然后powerpivot无法刷新工作表,但是我的宏继续执行,好像什么也没发生...

I'd like to know if there is a way to handle in VBA such an error in order to loop the refreshing process until it is fully and properly executed. 我想知道是否有一种方法可以在VBA中处理这样的错误,以便循环刷新过程,直到完全正确地执行它。

The simplest and most straight forward way I would suggest is to use a boolean variable and assign in to yes if the powerPivot gets refreshed properly and false if it doesn't. 我建议的最简单,最直接的方法是使用布尔变量,如果正确刷新了powerPivot,则将其分配给yes,否则将其分配为false。 Thus only when the variable is true the macro will run. 因此,只有当变量为true时,宏才会运行。 An example is: 一个例子是:

  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

Thus only when powerpivot is fully refreshed the macro will run. 因此,只有在完全刷新powerpivot时,宏才会运行。 Otherwise not. 否则不行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM