we can write some “workarounds” with the following options On Error:
1. GoTo
2. (Resume) Next
3. Exit Sub/Function
Example 1
If .Show = True Then
On Error GoTo SameFile
TxtFile = Dir(.SelectedItems(1))
Sheets.Add.Name = TxtFile
SameFile:
If Err.Number = 1004 Then
MsgBox "The File you have chosen was already uploaded."
Exit Sub
End If
For someone, who is coding error’s exception for the first time, it might be a little weird, but we can call it however we want, my idea is Same File for this example.
If you want see a whole procedure after modifiaction:
Example 2
On Error GoTo ErrDescr
'----'
ErrDescr:
MsgBox Err.Description
Example 3
On Error GoTo ErrorWO
'----'
ErrorWO:
MsgBox "A program error has occurred!" & vbCrLf _
& "ErrorNumber: " & Err.Number & vbCrLf _
& "Description: " & Err.Description & vbCrLf _
& "Help: " & Err.HelpFile & vbCrLf _
& "Source: " & Err.Source
Err.Clear