I create an on Error handler. I am trying to print out what the error was. I think I must have the variable names wrong. I'm not getting anything for Erl, Err.Number and Err.Description
macOS 10.10.5. Word 2011 14.7.3 (170325) MS Visual Basic Version 14.7.3 (170325)
Here is my code:
Sub testErrorCode()
10 Debug.Print "...===...beginning of program....===..." & Format(Now(), "dd/mm/yyyy hh:mm:ss.ms")
340 On Error GoTo ErrHandler
350 fileString = "Doc doesn't exist.doc"
360 Debug.Print "fileString is " & fileString
370 Set objDoc = Documents.Open(fileName:=fileString)
ErrHandler:
On Error GoTo -1 ' clear error
' https://www.fmsinc.com/free/newtips/VBA/ErrorHandling/LineNumber.html
630 Debug.Print "--- error --- "
640 boxTheMsg = "While processing document " & strFile & " An error occured ." & vbCrLf4
650 boxTheMsg = boxTheMsg & "Error Line: " & Erl & vbCrLf
670 boxTheMsg = boxTheMsg & "Error: (" & Err.Number & ") " & Err.Description
680 Debug.Print "boxTheMsg is " & boxTheMsg
690 MsgBox boxTheMsg, vbCritical
End Sub
Here is what I see on the output.
...===...beginning of program....===...18/07/2018 16:42:31.731
fileString is Doc doesn't exist.doc
--- error ---
boxTheMsg is While processing document An error occured .Error Line: 0
Error: (0)
See the attachment the uncaught message and what I got with the on error statement.
Robert