2top
asked on
File already open
I recently added an Add-On entitled "MouseWheel Fix". Since doing that my On Error routines no longer work. I went to MSDN On Error statement and added the Code Snippet shown below to my code. When executed, I get a "File already open" error message at the Kill "TESTFILE" line. Program control ignores the error handler routine. The code I use in my applications is very similiar to the OnErrorStatementDemo shown below. Neither of them work. Am I doing something wrong or has the Add-On somehow affected my system?
Sub OnErrorStatementDemo()
Dim objectref As Object
Dim msg As String
On Error GoTo ErrorHandler ' Enable error-handling routine.
Open "TESTFILE" For Output As #1 ' Open file for output.
Kill "TESTFILE" ' Attempt to delete open
' file.
On Error GoTo 0 ' Turn off error trapping.
On Error Resume Next ' Defer error trapping.
objectref = GetObject("MyWord.Basic") ' Try to start nonexistent
' object, then test for
'Check for likely Automation errors.
If Err.Number = 440 Or Err.Number = 432 Then
' Tell user what happened. Then clear the Err object.
msg = "There was an error attempting to open the Automation object!"
MsgBox msg, , "Deferred Error Test"
Err.Clear ' Clear Err object fields
End If
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
Select Case Err.Number ' Evaluate error number.
Case 55 ' "File already open" error.
Close #1 ' Close open file.
Case Else
' Handle other situations here...
End Select
Resume ' Resume execution at same line
' that caused the error.
End Sub
did you try to add a breakpoint to check if the error handler works?
ASKER
Thanks for your response! Yes, I stopped on the On Error statement and stepped the next two statements. It errs on the Kill statement but never goes to the ErrorHandler routine.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I didn't fully understand the options on the General tab. It seemed to me that Break on all Errors was correct. It was set that way and I changed it to Break on Unhandled Errors and now my Error Handling works! Thank you!!