I have a code that open another workbook based on today date. I plan to use task scheduler to auto run but in the case of the external workbook not found, I want my workbook to auto close so it wouldnt stuck there opened. But i encounter error message `Sorry we couldn't open 'D:\Users......."'. Anyway to suppress this error message?
Sub DataGrab()
On Error GoTo ErrorHandler
Dim extwbk As Workbook, twb As Workbook
Set twb = ThisWorkbook
Set extwbk = Workbooks.Open("D:\Users\Desktop\Report " & Format(Now, "DD-MMM-YYYY") & ".xls*", UpdateLinks:=0)
'
'my code
'
Exit Sub
ErrorHandler:
Application.DisplayAlerts = False
Application.Quit
Application.DisplayAlerts = True
End Sub
DisplayAlerts
before the problem might happen, not in the error handling code. By then it's too late. It also makes no sense to turnDisplayAlerts
back on after you quit the application. – Ken WhiteDir()
– braX