0

I've used Global variables in Excel VBA and have found that they haven't persisted throughout the session. My question is if it is because of something wrong I did, or do they not always stay for the whole Excel session?

Thanks for any clarification.

Community
  • 1
  • 1
Abe Gold
  • 2,307
  • 17
  • 29
  • Where did you declare it? Why did you say it did not persist or retain it's value? Can you show example so we can replicate it? As far as I know, public variables or you can call it global retain its value in the whole excel session, same instance. – L42 May 16 '14 at 14:57
  • 1
    Globals persist as long as the VBA isn't halted (e.g. by an unhandled error) – Tim Williams May 16 '14 at 16:41
  • Thank you, Tim. I believe that's the answer. – Abe Gold May 16 '14 at 21:48

2 Answers2

0

Tim Williams answered the question.

Globals persist as long as the VBA isn't halted (e.g. by an unhandled error) –  Tim Williams 

Thank you, Tim.

Abe Gold
  • 2,307
  • 17
  • 29
0

You are suffering from the VBA State Loss problem

I have solved this here In Excel VBA how to persist key variables over a 'state loss' (without writing to a cell or a file)?

Community
  • 1
  • 1
S Meaden
  • 8,050
  • 3
  • 34
  • 65