VBA在单独的excel实例中捕获错误

我写了一个VBA程序,它打开,刷新,保存并closures大量的包含数据透视表的Excel文件。 代码循环遍历每个报告,在一个单独的excel实例中打开它,并刷新它以及其他任务。 我有一个error handling程序捕获错误产生,如果它不能find该文件,如果该文件是只读的,但我想扩大它捕获错误,可能在刷新/保存步骤中产生的。

问题是因为这些错误发生在Excel的“刷新实例”中,而error handling程序位于Excel的“控制实例”中,所以不会捕获它们。 有谁知道如何捕捉另一个Excel实例中的错误?

Errorhandler: errorText = StandardPivots(1, myIndex) Failed(failedIndex) = errorText failedIndex = failedIndex + 1 objXL.Application.DisplayAlerts = False objXL.Quit Resume Next End Sub 

StandardPivots是一个变体,用于保存要刷新的报告。 失败是一个数组string,将容纳错误的文件的列表objXL指的是我的Excel的“刷新实例”

它需要在一个单独的Excel实例中,因为我有一个方法,用户可以closures需要随时访问的进程(而不是像文件刷新时那样locking)

以防万一它是有用的。 以下是我如何处理最后的错误:

 If failedIndex = 0 Then OutputMsg = "All " & RefreshType & " Pivots Refreshed" ActiveWorkbook.Sheets("Control").Range("E25").Value = OutputMsg 'Just in case e-mail process fails, pivots which failed are output to excel Produce_Email Else For x = 0 To failedIndex - 1 OutputMsg = OutputMsg + Failed(x) & ", " Next x OutputMsg = Left(OutputMsg, Len(OutputMsg) - 2) ActiveWorkbook.Sheets("Control").Range("E25").Value = OutputMsg Produce_Email ' Main module 

让我知道如果你还需要别的东西吗?

感谢您的任何帮助,您可以提供。