Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Excel loses mind clearing VBA global variables

Ive inherited a large Excel and Access application that has been grown over
time by a number of individual developers. The major issue I need to resolve
is the use or abuse of global variables. This application uses VBA global
variables rather than storing data on hidden worksheets. Also, all data is
loaded into arrays €“ VBA global variables €“ from an Access database when the
application starts. There are many places in the code that checks that the
global variables are still populated and if not then the application is
automatically restarted.

I can not redesign and rewrite this application from scratch. I have to find
ways to mitigate the risk of a restart. I need a list of things, events, etc.
that can cause Excel to clear VBA global variables so I can €śdance around€ť
these €śthings.€ť

Inserting objects onto a sheet may be one thing. Adding and deleting sheets
may be another. My problems began with using VBA to insert a combo box onto a
sheet right after code that inserted action buttons. I now am using a
template and have removed the code that inserts these objects. VBA adds a new
sheet using the template. All the objects and formulae work. The data in the
global variables is present and is inserted into the new sheet. Now when I
click the menu option to do the same process again, all the global variables
are cleared. The first step of this process looks for sheets left from
previous executions and deletes them. This appears to be the place where
Excel resets. Also, Excel announces at the point where a sheet is to be
deleted that break mode can not continue and provides an option to continue
code execution or end. Is there a way to preserve Excels state through sheet
deletion or should I go through the application and see about reusing sheets
rather than deleting them?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Excel loses mind clearing VBA global variables

The first thing to look for is the stand alone code line "End". That one
clears globals. Other than that I know of nothing specific that clears
globals but then again I avoid globals wherever possible. I would suspect
that code which adds or deletes code would be an issue.
--
HTH...

Jim Thomlinson


"Pictou" wrote:

Ive inherited a large Excel and Access application that has been grown over
time by a number of individual developers. The major issue I need to resolve
is the use or abuse of global variables. This application uses VBA global
variables rather than storing data on hidden worksheets. Also, all data is
loaded into arrays €“ VBA global variables €“ from an Access database when the
application starts. There are many places in the code that checks that the
global variables are still populated and if not then the application is
automatically restarted.

I can not redesign and rewrite this application from scratch. I have to find
ways to mitigate the risk of a restart. I need a list of things, events, etc.
that can cause Excel to clear VBA global variables so I can €śdance around€ť
these €śthings.€ť

Inserting objects onto a sheet may be one thing. Adding and deleting sheets
may be another. My problems began with using VBA to insert a combo box onto a
sheet right after code that inserted action buttons. I now am using a
template and have removed the code that inserts these objects. VBA adds a new
sheet using the template. All the objects and formulae work. The data in the
global variables is present and is inserted into the new sheet. Now when I
click the menu option to do the same process again, all the global variables
are cleared. The first step of this process looks for sheets left from
previous executions and deletes them. This appears to be the place where
Excel resets. Also, Excel announces at the point where a sheet is to be
deleted that break mode can not continue and provides an option to continue
code execution or end. Is there a way to preserve Excels state through sheet
deletion or should I go through the application and see about reusing sheets
rather than deleting them?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Excel loses mind clearing VBA global variables

First thing I did was look for standalone "End" statements. I have narrowed
the issue to delete of sheets and charts from the workbook. That seems to
cause an implicit "End." Of course, the version of the application from
before I started is working fine with no clearing of global variables.

I inherited this application so I have to find mitigating strategies. Right
now I plan to hide the unneeded sheets and charts rather than delete them and
change the code to look for existing sheets and charts and reuse those rather
add new ones.

Since the application was "working" before I got into it, I am the goat who
has broken it.

"Jim Thomlinson" wrote:

The first thing to look for is the stand alone code line "End". That one
clears globals. Other than that I know of nothing specific that clears
globals but then again I avoid globals wherever possible. I would suspect
that code which adds or deletes code would be an issue.
--
HTH...

Jim Thomlinson


"Pictou" wrote:

Ive inherited a large Excel and Access application that has been grown over
time by a number of individual developers. The major issue I need to resolve
is the use or abuse of global variables. This application uses VBA global
variables rather than storing data on hidden worksheets. Also, all data is
loaded into arrays €“ VBA global variables €“ from an Access database when the
application starts. There are many places in the code that checks that the
global variables are still populated and if not then the application is
automatically restarted.

I can not redesign and rewrite this application from scratch. I have to find
ways to mitigate the risk of a restart. I need a list of things, events, etc.
that can cause Excel to clear VBA global variables so I can €śdance around€ť
these €śthings.€ť

Inserting objects onto a sheet may be one thing. Adding and deleting sheets
may be another. My problems began with using VBA to insert a combo box onto a
sheet right after code that inserted action buttons. I now am using a
template and have removed the code that inserts these objects. VBA adds a new
sheet using the template. All the objects and formulae work. The data in the
global variables is present and is inserted into the new sheet. Now when I
click the menu option to do the same process again, all the global variables
are cleared. The first step of this process looks for sheets left from
previous executions and deletes them. This appears to be the place where
Excel resets. Also, Excel announces at the point where a sheet is to be
deleted that break mode can not continue and provides an option to continue
code execution or end. Is there a way to preserve Excels state through sheet
deletion or should I go through the application and see about reusing sheets
rather than deleting them?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Global Variables Karen53 Excel Programming 12 April 16th 08 07:14 PM
Global Variables in Excel VBA [email protected] Excel Programming 6 November 6th 06 11:21 AM
Global Variables [email protected] Excel Programming 0 July 7th 06 10:53 AM
global variables Mike Archer Excel Programming 4 May 3rd 06 07:33 PM
Global Variables Ernst Guckel[_4_] Excel Programming 2 May 7th 05 11:10 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"