ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Out of Scope Errors when exiting Excel (https://www.excelbanter.com/excel-programming/421484-out-scope-errors-when-exiting-excel.html)

Steve McLeod

Out of Scope Errors when exiting Excel
 
I have worksheets with controls and associated event code. When I exit the
Excel I am getting compiler errors in code that references controls and other
objects that have gone out of scope while Excel is shutting down. The VBA
code that is flagged as in error is not consistently the same. How do I get
Excel to shut down without the need to click the "End" button in the VBA
debugger prompt?
--
Pictou

Peter T

Out of Scope Errors when exiting Excel
 
You shouldn't have to use the End button (except in development) or the End
statement ever.

Impossible to say much more without the code, but in general ensure all
object references that will not go out of scope automatically (most do) are
released.

Regards,
Peter T

"Steve McLeod" wrote in message
...
I have worksheets with controls and associated event code. When I exit the
Excel I am getting compiler errors in code that references controls and
other
objects that have gone out of scope while Excel is shutting down. The VBA
code that is flagged as in error is not consistently the same. How do I
get
Excel to shut down without the need to click the "End" button in the VBA
debugger prompt?
--
Pictou




Steve McLeod

Out of Scope Errors when exiting Excel
 
I click the File menu and then Exit. Excel starts shutting down. While
shutting down Excel VBA flags objects as missing and opens the debugger.
Sometimes the flagged code is a reference to a control on a sheet, sometimes
it is a global variable, and sometimes it is a sheet reference, and sometimes
Excel exits without starting the debugger. The "End" button is the one on
the debugger prompt that permits the user to enter debugging or just end
execution.

The only reason these errors can occur is that Excel has closed the
referenced object prior to scanning the code that references it. This is
stupid. Why worry about object references when all of them are being closed?
Why try to execute a control event when the application is closing?

--
Pictou


"Steve McLeod" wrote:

I have worksheets with controls and associated event code. When I exit the
Excel I am getting compiler errors in code that references controls and other
objects that have gone out of scope while Excel is shutting down. The VBA
code that is flagged as in error is not consistently the same. How do I get
Excel to shut down without the need to click the "End" button in the VBA
debugger prompt?
--
Pictou


Peter T

Out of Scope Errors when exiting Excel
 
Pretty sure there's something specific to your particular code, normally
shouldn't be any problem even with those references, at least in the way I
imagine they exist.

As I mentioned before, impossible to say what's wrong without some idea of
the code.

Regards,
Peter T

"Steve McLeod" wrote in message
...
I click the File menu and then Exit. Excel starts shutting down. While
shutting down Excel VBA flags objects as missing and opens the debugger.
Sometimes the flagged code is a reference to a control on a sheet,
sometimes
it is a global variable, and sometimes it is a sheet reference, and
sometimes
Excel exits without starting the debugger. The "End" button is the one on
the debugger prompt that permits the user to enter debugging or just end
execution.

The only reason these errors can occur is that Excel has closed the
referenced object prior to scanning the code that references it. This is
stupid. Why worry about object references when all of them are being
closed?
Why try to execute a control event when the application is closing?

--
Pictou


"Steve McLeod" wrote:

I have worksheets with controls and associated event code. When I exit
the
Excel I am getting compiler errors in code that references controls and
other
objects that have gone out of scope while Excel is shutting down. The VBA
code that is flagged as in error is not consistently the same. How do I
get
Excel to shut down without the need to click the "End" button in the VBA
debugger prompt?
--
Pictou





All times are GMT +1. The time now is 01:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com