View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] paul.robinson@it-tallaght.ie is offline
external usenet poster
 
Posts: 789
Default Public Variables

Hi
You can declare variables as public at the top of any code module &
they will be available to all modules.
If you want TodaysDate to be a date or a string, then declare it as a
Variant.

You might want to pause and rethink your strategy here though. When it
comes to managing a lot of code in several modules & you have some
debugging to do on a code rewrite you will dearly, dearly wish you
hadn't gone down this road...
More than that, I would put as much commentary as I could next to each
variable as it is declared to tell me exactly what it is for.

regards
Paul

On Jul 3, 10:30*am, Richard wrote:
Hi,

I understand the reason for declaring variables, but get fed up with
declaring them for each Sub in each module. *

Can I declare my vaiables in 'This Workbook' using public.
Can I also 'publicly' declare what the vaiable refers to so that if I do the
following

Public TodaysDate As String

that I could use

TodaysDate = Worksheets("Dates").range("UpdateToday")
TodaysDate = Format(TodaysDate, "dd-mmm-yy")

in any module/sub.

Unfortunately I have to work with dates that are strings and others that are
dates in various formats.

Thanks for any help / advice

Richard