Maintain Public Variable Values Across ALL Open Excel Workbooks

Everything I read says that Excel Public VBA variables should retain their values across all open workbooks.  I created two new, simple workbooks (Test1.xlsm & Test2.xlsm) with identical code:

Public Test As Boolean

Sub SetVarTrue()
  Test = True
End Sub

Sub SetVarFalse()
  Test = False
End Sub

If I activate Test1.xlsm & run "SetVarTrue", it changes the value of Test ONLY in Test1.xlsm .  If I switch to Test2.xlsm, the value of Test remains "False".  Works the same if I change the value in Test2.

How can I make Test TRULY PUBLIC across both workbooks?

Thank you.
Wayne KaniewskiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlanConsultantCommented:
Hi Wayne,

Maybe I am wrong, but I have always considered public variables / constants to be workbook based, so your test is exactly what I would have expected.

Alan.
1
Martin LissOlder than dirtCommented:
You can't do that.
0
AlanConsultantCommented:
Hi Wayne,

If you need to maintain cross-workbook variables, you could create a single workbook to hold those, and do nothing much else, then explicitly pull them from there wherever needed?

Alan.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
The only thing that I can think of to do it would be to create a file that contains the yes/no value and have the workbooks read it when they open and update it when they close.
1
Wayne KaniewskiAuthor Commented:
Thank you Alan!  I feared that, but at least I have an answer & can quit banging my head against the wall.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.