I'm getting an error stating that there is a "Runtime error '1004': cannot access '***.csv'. The window that this error is displaying in has the buttons "End" "Debug" and "Help". This is the code:
Public Flag As Boolean
Sub ReRun()
nextRun = Now + TimeValue("00:00:03")
Application.OnTime nextRun, "ReRun"
Call saveworkbook
End Sub
Sub StartMacro()
'Run this macro to start "YourMacro"
Flag = False
Call ReRun
End Sub
Sub Auto_Close()
'Turns off the OnTime event when closing the file
Call StopMacro
End Sub
Sub StopMacro()
'Run this to turn off the OnTime event
On Error Resume Next
Application.OnTime nextRun, "ReRun", schedule:=False
End Sub
Sub saveworkbook()
If Flag = False Then
Flag = True
ActiveWorkbook.SaveAs Filename:="c:\folder\filename.csv", FileFormat:=xlCSV
Else
ActiveWorkbook.Save
End If
End Sub
When the "Debug" button is clicked the error points to ActiveWorkbook.Save
The user then has to shut down the macro and then rerun it. Is there any way to have it catch the error and retry?
Bookmarks