I have been reading up a little and it seems that this may be a bug....
Here is what is happening: I have error handling code that should avoid an error message.
The first time I have an error, however, it throws error 91: Object Variable or With Block Variable Not set
Then, any other time after that, the error handling code works perfectly.
What is even more odd: If I set a break point and F8 my way through the code, the error never shows up and the error handling code works perfectly.
Here is my code. I found this neat piece of code that gets me the subroutine name as well as object name and module name:
On Error goto errhandler
.....code stuff, and calling a function. The error is occurring in the function.
Exit Sub
errhandler:
strObjName = CodeContextObject.Name
Application.VBE.ActiveCodePane.GetSelection merr, nerr, xerr, yerr
strModName = Application.VBE.ActiveCodePane.CodeModule
strProcName = Application.VBE.ActiveCodePane.CodeModule.ProcOfLine(merr, 0)
Call ErrHandlerPublic(strObjName, strModName, strProcName)
Exit Sub
All variables above are defined as public variables. I tried local ones too and it made no difference.
When it throws the error and I hit debug, it highlights this:
Application.VBE.ActiveCodePane.GetSelection merr, nerr, xerr, yerr
But again, if I hit F8 it completes the code perfectly.
Any help greatly appreciated!!!!
Here is what is happening: I have error handling code that should avoid an error message.
The first time I have an error, however, it throws error 91: Object Variable or With Block Variable Not set
Then, any other time after that, the error handling code works perfectly.
What is even more odd: If I set a break point and F8 my way through the code, the error never shows up and the error handling code works perfectly.
Here is my code. I found this neat piece of code that gets me the subroutine name as well as object name and module name:
On Error goto errhandler
.....code stuff, and calling a function. The error is occurring in the function.
Exit Sub
errhandler:
strObjName = CodeContextObject.Name
Application.VBE.ActiveCodePane.GetSelection merr, nerr, xerr, yerr
strModName = Application.VBE.ActiveCodePane.CodeModule
strProcName = Application.VBE.ActiveCodePane.CodeModule.ProcOfLine(merr, 0)
Call ErrHandlerPublic(strObjName, strModName, strProcName)
Exit Sub
All variables above are defined as public variables. I tried local ones too and it made no difference.
When it throws the error and I hit debug, it highlights this:
Application.VBE.ActiveCodePane.GetSelection merr, nerr, xerr, yerr
But again, if I hit F8 it completes the code perfectly.
Any help greatly appreciated!!!!