Global variable

ShieBoon

Board Regular
Joined
May 3, 2011
Messages
111
Hi all, is it possible to declare a variable in ThisWorkbook and use the variable in module procedures? Basically i want to create a global variable somewhere that allows me to use the variable in events, modules and procedures. i'm using excel 2003
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
... Basically i want to create a global variable somewhere that allows me to use the variable in events, modules and procedures. i'm using excel 2003

Declare a public variable in a general module, not in the workbook module or in a worksheet module.
 
Upvote 0
FYI< you can declare it in the workbook (or worksheet) module but then you have to refer to it as a member of that object - ThisWorkbook.Variablename for example rather than just variablename.
 
Upvote 0
Hi Rory

A bit of fanaticism for a nice start of the day. :)

It's true that you can declare a public variable in an object module (sadly, in my opinion). I think, however, that this goes against the object model paradigm, goes agains one of the fundamental characteristics of object oriented design, that is Encapsulation. In my opinion it's not good practice to declare public variables in a class. I go even as far as to say that it should even not be allowed by the syntax.
 
Upvote 0
I would agree completely but I thought that getting into Property procedures was probably a bit OTT for this discussion. ;)
As a return bit of dogma, public variables should be avoided if at all possible. :)
 
Upvote 0

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top