Application Event Scope Problem

M

mikehoar

I have an Add-In where I have created a class which holds a couple of
application level events. In the class I declare a public Application
object WithEvents. The class is instantiated in the Add-In
WorkBook_Open event. When I load a workbook with the Add-In attached
the events seem to fire ok on the workbook, it being the active
workbook. However, I have a form on the Add-In activated from a toolbar
button which is periodically displayed during a program loop for the
user to make a choice. On the form I have a button which stops the
program with the End keyword if the user wants to stop the program.
When this button is pressed the code stops running ok but so do the
application events.

Any help appreciated.
 
C

Chip Pearson

The End keyword should never be used. It completely terminates
all VBA code and reset all public variables to their default
values. You should instead use Exit Sub or Exit Function to exit
from the called procedure, perhaps returning a value indicating
to the calling procedure that it, too, should call Exit Sub.

In short, design your code so that End is never used.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
M

mikehoar

Thanks

Mike
Chip said:
The End keyword should never be used. It completely terminates
all VBA code and reset all public variables to their default
values. You should instead use Exit Sub or Exit Function to exit
from the called procedure, perhaps returning a value indicating
to the calling procedure that it, too, should call Exit Sub.

In short, design your code so that End is never used.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top