Littlemalky
Board Regular
- Joined
- Jan 14, 2011
- Messages
- 223
I'm trying to use an "On Error" for the first time to install some error handling. Basically, I want to open a file in a specific folder only if it has the current day's date in it, otherwise, i want to exit the sub and call upon another procedure within the module without displaying to me that the file doesn't exist in the location. I've figured out how to do this, but only by putting Application.DisplayAlerts around the open file line and I feel like I shouldn't have to do that with this code. Is this the only way, or am I missing something?
If i don't use the displayalerts line, it tells me the file is not in the specified location. I'm trying to avoid that alert so it just continues to run.
Code:
On Error GoTo ErrHandler
Application.DisplayAlerts = False
Workbooks.Open Filename:="...\FHR to SUB\FHR to SUB " & Format(Date, "yyyymmdd") & " - EDC.xlsx"
Application.DisplayAlerts = True
Range("B6").Formula = "='[FHR to SUB " & Format(Date, "yyyymmdd") & " - EDC.xlsx]Summary'!$D$31"
Range("B7").Formula = "=B6-'[FHR to SUB " & Format(Date, "yyyymmdd") & " - EDC.xlsx]Summary'!$D$36-'[FHR to SUB " & Format(Date, "yyyymmdd") & " - EDC.xlsx]Summary'!$D$47"
Workbooks("FHR to SUB " & Format(Date, "yyyymmdd") & " - EDC.xlsx").Close False
Call EDCSUBtoCUS
Exit Sub
ErrHandler:
Call EDCSUBtoCUS
Exit Sub
If i don't use the displayalerts line, it tells me the file is not in the specified location. I'm trying to avoid that alert so it just continues to run.