I have a program that requires a lot of Workbook.Save and Workbook.Open operations through out the day.
Most of time the program works ok, but once or twice a week, it stops with "fail to open / save object" errors on the Workbook.Save or Workbook.Open line for no obvious reasons (such as windows 7 thinks the file is already opened when it's not).
Clicking "Debug" and the "Play" button usually allows the program to work again, as the program will then successfully open/save the workbooks.
This is not what I want, because it causes interruption and requires manual operations.
I tried the following code using error handling to do the file operations five times before reporting errors, but it didn't work:
Application.DisplayAlerts = False
For numErrTry = 0 To 5
If numErrTry = 5 Then
On Error GoTo 0
Else
On Error Resume Next
End If
The WB.Save or WB.Open Line here
If Err.Number = 0 Then
Exit For
Else
Sleep 5000
End If
Next numErrTry
On Error GoTo 0
Application.DisplayAlerts = True
Are there other solutions to these occasion errors when doing workbook.save/open operations?
Thanks.
Most of time the program works ok, but once or twice a week, it stops with "fail to open / save object" errors on the Workbook.Save or Workbook.Open line for no obvious reasons (such as windows 7 thinks the file is already opened when it's not).
Clicking "Debug" and the "Play" button usually allows the program to work again, as the program will then successfully open/save the workbooks.
This is not what I want, because it causes interruption and requires manual operations.
I tried the following code using error handling to do the file operations five times before reporting errors, but it didn't work:
Application.DisplayAlerts = False
For numErrTry = 0 To 5
If numErrTry = 5 Then
On Error GoTo 0
Else
On Error Resume Next
End If
The WB.Save or WB.Open Line here
If Err.Number = 0 Then
Exit For
Else
Sleep 5000
End If
Next numErrTry
On Error GoTo 0
Application.DisplayAlerts = True
Are there other solutions to these occasion errors when doing workbook.save/open operations?
Thanks.
Last edited: