Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Lifetime of VBA variables

I use VBA with Excel; I do not use VB.

My Visual Basic User's Manual says that Module-level variables retain
their values while Visual Basic is running. Does that mean as long as
Excel is open? Or as long as an Excel workbook is open? Or something else?

Thanks,
Alan Beban
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Lifetime of VBA variables

They retain their value for as long as the workbook is open... The same is
true of static variables...

"Alan Beban" wrote:

I use VBA with Excel; I do not use VB.

My Visual Basic User's Manual says that Module-level variables retain
their values while Visual Basic is running. Does that mean as long as
Excel is open? Or as long as an Excel workbook is open? Or something else?

Thanks,
Alan Beban

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Lifetime of VBA variables

Jim Thomlinson wrote:
They retain their value for as long as the workbook is open... The same is
true of static variables...


Thank you.

Alan Beban

"Alan Beban" wrote:


I use VBA with Excel; I do not use VB.

My Visual Basic User's Manual says that Module-level variables retain
their values while Visual Basic is running. Does that mean as long as
Excel is open? Or as long as an Excel workbook is open? Or something else?

Thanks,
Alan Beban

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Lifetime of VBA variables

What Jim Thomlinson wrote has a 'kinda...' to it.

Module level variables retain their values as long as the workbook is
open *and* there is no unhandled fault in the code.

Also known (documented?) is a bug wherein all global variables lose
their values when one programmatically adds (deletes? does something
else to?) a control in an userform. I suspect there are other cases
where module level variables are reset -- intentionally or otherwise.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Jim Thomlinson wrote:
They retain their value for as long as the workbook is open... The same is
true of static variables...


Thank you.

Alan Beban

"Alan Beban" wrote:


I use VBA with Excel; I do not use VB.

My Visual Basic User's Manual says that Module-level variables retain
their values while Visual Basic is running. Does that mean as long as
Excel is open? Or as long as an Excel workbook is open? Or something else?

Thanks,
Alan Beban


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Lifetime of VBA variables

Just to add -

I suspect there are other cases
where module level variables are reset -- intentionally or otherwise.


Particularly in XL97, an unhandled error in a UDF, even in another workbook,
can cause all code to terminate and all public variables destroyed. When I
say terminate - just stop.

In "our" otherwise perfect code & wb, no way of knowing if user has UDF's in
other wb's liable to fail. Means disabling calculation if code is going to
trigger a calculation event. While "our" code is not running, no way of
knowing what may have occurred in the meantime to destroy any public var's.

I'm almost sure I've experienced similar in XL2K but cannot now recreate the
problem in later versions.

Also known (documented?) is a bug wherein all global variables lose
their values when one programmatically adds (deletes? does something
else to?) a control in an userform.


Also adding manually or with code ActiveX controls to a worksheet, in some
but not all scenarios, can cause recompile (advised to me by Stephen Bullen
in another thread).

Regards,
Peter T

"Tushar Mehta" wrote in message
om...
What Jim Thomlinson wrote has a 'kinda...' to it.

Module level variables retain their values as long as the workbook is
open *and* there is no unhandled fault in the code.

Also known (documented?) is a bug wherein all global variables lose
their values when one programmatically adds (deletes? does something
else to?) a control in an userform. I suspect there are other cases
where module level variables are reset -- intentionally or otherwise.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Jim Thomlinson wrote:
They retain their value for as long as the workbook is open... The

same is
true of static variables...


Thank you.

Alan Beban

"Alan Beban" wrote:


I use VBA with Excel; I do not use VB.

My Visual Basic User's Manual says that Module-level variables retain
their values while Visual Basic is running. Does that mean as long as
Excel is open? Or as long as an Excel workbook is open? Or something

else?

Thanks,
Alan Beban




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
scope/ lifetime of variable jeffP Excel Programming 5 September 19th 04 05:25 AM
scope/ lifetime of variable Norman Jones Excel Programming 0 September 18th 04 12:55 AM
!!!! A chance of a lifetime !!! Good Excel Programming 0 June 3rd 04 06:14 AM
!!!! A chance of a lifetime !!! Good Excel Programming 0 June 3rd 04 06:14 AM
module-level variable lifetime Jessie[_2_] Excel Programming 0 July 30th 03 09:31 PM


All times are GMT +1. The time now is 09:36 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"