Intermittent Error on Application.EnableEvents

seedyn

New Member
Joined
Jul 1, 2008
Messages
1
I have developed a VBA app in Excel to collect data from several PLCs in a factory and depositing the counts into a worksheet for subsequent part counting and reconciliation. I use an ActiveX Timer called 'VBA Timer' to synchronize the time when the PLC data is read.

During this read event, the Events are disabled using the line:
Application.EnableEvents = False

On rare instances it produces an error:
Run-time error 50290
Method 'EnableEvents' of object '_Application' Failed

It could go anywhere from 1 week to 2 months before the error occurs.

I am really stumped on this one. I would appreciate any help in solving this problem.

Kind Regards,
Curt
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
After researching this it looks that it may have something to do with Excel not having focus when it is set to run by the ActiveX Timer. When I googled Run-time error 50290, it kept leading to the timer and Excel not being in focus, but that may not be the actual problem, but I would search the internet for the exact error message and see if you find any similarities between what others are saying and maybe what your code is doing?

Hope that helps.
 
Upvote 0
After researching this it looks that it may have something to do with Excel not having focus when it is set to run by the ActiveX Timer. When I googled Run-time error 50290, it kept leading to the timer and Excel not being in focus, but that may not be the actual problem, but I would search the internet for the exact error message and see if you find any similarities between what others are saying and maybe what your code is doing?

Hope that helps.

I get this same error intermittently within the "AfterSave" Workbook Event , even when Excel does have the focus, so Excel not having the focus is NOT the reason for this error to pop up. I haven't figured out what exactly is causing the error on the line:

Code:
Application.EnableEvents = False

One such reason why I have the code in there, I have it update the worksheet I am working on with a couple of pieces. If I didn't incorporate this line of code bear the beginning and the same line, but only setting this workbook property back to "True", near the end of the event as well within the change events, it would cause the Change event on both levels, the workbook and worksheet levels, to go into a continuous loops, thus would cause the stack to run out of space, and the application to crash. This error only happens AFTER the workbook has been saved, not when data within any cell within the workbook has been saved.

Though I hate having to use the method I used, but I ended up using the In-line method of error handling (On Error Resume Next), and have it skip the lines of codes to record into the current worksheet, if Err.Number <> 0; then put it back to the normal erring out process (On Error Goto 0) after the error has been cleared out (Err.Clear). But this also means I lack having that current data there in the worksheet as a work around to this issue, as this doesn't fix the issue.
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,085
Members
448,548
Latest member
harryls

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top