rccharles
07-18-2018, 02:20 PM
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()
Debug.Print "...===...beginning of program....===..." & Format(Now(), "dd/mm/yyyy hh:mm:ss.ms")
On Error GoTo ErrHandler
fileString = "Doc doesn't exist.doc"
Debug.Print "fileString is " & fileString
Set objDoc = Documents.Open(fileName:=fileString)
ErrHandler:
On Error GoTo -1 ' clear error
' https://www.fmsinc.com/free/newtips/VBA/ErrorHandling/LineNumber.html
Debug.Print "--- error --- "
boxTheMsg = "While processing document " & strFile & " An error occured ." & vbCrLf4
boxTheMsg = boxTheMsg & "Error Line: " & Erl & vbCrLf
boxTheMsg = boxTheMsg & "Error: (" & Err.Number & ") " & Err.Description
Debug.Print "boxTheMsg is " & boxTheMsg
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
macOS 10.10.5. Word 2011 14.7.3 (170325) MS Visual Basic Version 14.7.3 (170325)
Here is my code:
Sub testErrorCode()
Debug.Print "...===...beginning of program....===..." & Format(Now(), "dd/mm/yyyy hh:mm:ss.ms")
On Error GoTo ErrHandler
fileString = "Doc doesn't exist.doc"
Debug.Print "fileString is " & fileString
Set objDoc = Documents.Open(fileName:=fileString)
ErrHandler:
On Error GoTo -1 ' clear error
' https://www.fmsinc.com/free/newtips/VBA/ErrorHandling/LineNumber.html
Debug.Print "--- error --- "
boxTheMsg = "While processing document " & strFile & " An error occured ." & vbCrLf4
boxTheMsg = boxTheMsg & "Error Line: " & Erl & vbCrLf
boxTheMsg = boxTheMsg & "Error: (" & Err.Number & ") " & Err.Description
Debug.Print "boxTheMsg is " & boxTheMsg
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