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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
... 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,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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