Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Maintaining variables after program ends

My macro is triggered on Worksheet_Activate, and stores the contents of
several cells in an array. Later, when a button is clicked, another macro is
a standard module uses the variables in the array in a dialog box. It worked
for a while, but now, for some reason, as soon as the Worksheet_Activate
macro ends, the array values revert to Empty. I've tried declaring the array
in the worksheet code, the module code, and as Public, but nothing seems to
restore its earlier functionality. Where should the declaration be placed?

Goody
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Maintaining variables after program ends

If you stop the macro manually (usually while testing) by clicking the Reset
button (or Run|Reset from the menubar), then those public/static variables are
lost/reset to defaults.

If you use "End" to quit the macro (not "End Sub", "End If", "End Function",
....), then you'll reset those variables.

I'm gonna guess that you tried to quickly quit your code by using End and lost
the values your variables held.

Goody wrote:

My macro is triggered on Worksheet_Activate, and stores the contents of
several cells in an array. Later, when a button is clicked, another macro is
a standard module uses the variables in the array in a dialog box. It worked
for a while, but now, for some reason, as soon as the Worksheet_Activate
macro ends, the array values revert to Empty. I've tried declaring the array
in the worksheet code, the module code, and as Public, but nothing seems to
restore its earlier functionality. Where should the declaration be placed?

Goody


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Maintaining variables after program ends

Goody:

One process I use frequently to initialize and PRESERVE all the variables I
want to be GLOBAL is to initialize them at Excel worksheet startup time.

From your VBA area, Insert a Module, then Insert a Procedure, and name it
Auto_Open.

Once you define Public variables in that manner, they persists and can be
viewed/modified by forms and worksheets.

Here's an example:

Option Explicit
Option Base 1
Public dteDateSelected As Date
Public intNumberOfTransactionRows As Long
Public intNumberOfTemplateRows As Long
Public strStyleAnalysisFilter As String
Public strColorAnalysisFilter As String
Public strFactoryFilter As String
Public strMailToEmailAddress As String
Public strCCEmail As String
Public strToggleFilter As Boolean

Public Sub Auto_Open()
Dim intFullArrayEntries As Long
Dim intAllFactoryEntries As Long
Dim intBuildAllArray As Long
Dim intNumberOfRowsInTransWorksheet As Long
Dim intNumberOfRowsInTemplateWorksheet As Long
Dim intBuildEmailAddress As Long

dteDateSelected = Date
intNumberOfTransactionRows = 2
strStyleAnalysisFilter = ""
strColorAnalysisFilter = ""
strFactoryFilter = ""
strTemplateWorkbookName = ActiveWorkbook.Name
strMailToEmailAddress = ""
strCCEmail = ""
strToggleFilter = True

.... More Code

--
Rich Locus
Logicwurks, LLC


"Goody" wrote:

My macro is triggered on Worksheet_Activate, and stores the contents of
several cells in an array. Later, when a button is clicked, another macro is
a standard module uses the variables in the array in a dialog box. It worked
for a while, but now, for some reason, as soon as the Worksheet_Activate
macro ends, the array values revert to Empty. I've tried declaring the array
in the worksheet code, the module code, and as Public, but nothing seems to
restore its earlier functionality. Where should the declaration be placed?

Goody

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Maintaining variables after program ends

If you are using VBA/Excel, use cells on a worksheet instead of MyArray().



"Goody" wrote in message
...
My macro is triggered on Worksheet_Activate, and stores the contents of
several cells in an array. Later, when a button is clicked, another macro
is
a standard module uses the variables in the array in a dialog box. It
worked
for a while, but now, for some reason, as soon as the Worksheet_Activate
macro ends, the array values revert to Empty. I've tried declaring the
array
in the worksheet code, the module code, and as Public, but nothing seems
to
restore its earlier functionality. Where should the declaration be placed?

Goody


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
Execution ends without error message in middle of program Richard J. Snee Excel Programming 3 June 11th 07 05:37 AM
filter using "ends with" and 3 choices? Ex: ends with 1,2 or3 Debbie Excel Worksheet Functions 1 April 6th 07 12:07 AM
Maintaining relationship between 3 variables [email protected] Excel Programming 4 September 18th 06 08:07 AM
Loop never ends Bernie Deitrick Excel Programming 0 June 30th 04 07:00 PM
Input variables on Sheet1 being called by a VB program on Sheet 2 RU42 Excel Programming 1 August 23rd 03 09:50 AM


All times are GMT +1. The time now is 10:48 PM.

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

About Us

"It's about Microsoft Excel"