P
PaulFryer
I am using XL 2004 (v.11.2.3) and Visual basic for Applications (VBA)
11.2 for Macintosh, and want to do something which should be real
simple - except that I can't find a way! I would really appreciate
help on how to set about this or what I might be doing wrong.
I need to write a module containing 3 simple VBA functions to call from
an XL spreadsheet, which all need access to a 4 x 25 element array of
constants. These constants never change, but are hard to calculate.
How do I make such a table available to all 3 Functions? I have tried:
· Various ways of entering data, of the form "Dim table(4,25) =
{0,1,2,3;4,5,6,7;8 . . . . etc}", or "Const table(0,0) =0, . .. . .
etc" at the module level, but all are rejected by the VBA compiler. It
appears that you can only set simple names as constants - not array
elements. VBA Help is no use at all.
· Defining a Static array at the module level, and then calling a
dummy routine in the module once from the spreadsheet to initialize all
4x25 elements. But you can't have Static variables at the module
level, and if I put the Static array inside the initializing routine
it's obviously not available to the 3 main functions.
· Passing the 4 x 25 array as an argument to each of the 3
Functions, and having the array of constants on the spreadsheet
instead. However, passing arrays (by reference) to VBA functions
doesn't seem to work at all - the VBA code doesn't even begin to
execute, and I get a #VALUE returned to the calling spreadsheet cell.
I must be doing something wrong here, but I can't see what, and I would
appreciate suggestions.
What I really don't want to do is to individually initialize all 4 x 25
constants each time I call any of the 3 Functions, as these functions
are extensively used on the spreadsheet and this would slow down
operation significantly. And this really is an ugly, brute-force way
of doing things!
I have had these 3 routines using the old Macro language from Excel 4.0
days, but this is fairly ugly using two linked XL documents, and I want
to make the whole spreadsheet available to other people, including some
Windows users. Hence I thought I would try and update them to VBA.
So, please, please, suggestions as to how I set about this simple task.
Thanks,
Paul.
11.2 for Macintosh, and want to do something which should be real
simple - except that I can't find a way! I would really appreciate
help on how to set about this or what I might be doing wrong.
I need to write a module containing 3 simple VBA functions to call from
an XL spreadsheet, which all need access to a 4 x 25 element array of
constants. These constants never change, but are hard to calculate.
How do I make such a table available to all 3 Functions? I have tried:
· Various ways of entering data, of the form "Dim table(4,25) =
{0,1,2,3;4,5,6,7;8 . . . . etc}", or "Const table(0,0) =0, . .. . .
etc" at the module level, but all are rejected by the VBA compiler. It
appears that you can only set simple names as constants - not array
elements. VBA Help is no use at all.
· Defining a Static array at the module level, and then calling a
dummy routine in the module once from the spreadsheet to initialize all
4x25 elements. But you can't have Static variables at the module
level, and if I put the Static array inside the initializing routine
it's obviously not available to the 3 main functions.
· Passing the 4 x 25 array as an argument to each of the 3
Functions, and having the array of constants on the spreadsheet
instead. However, passing arrays (by reference) to VBA functions
doesn't seem to work at all - the VBA code doesn't even begin to
execute, and I get a #VALUE returned to the calling spreadsheet cell.
I must be doing something wrong here, but I can't see what, and I would
appreciate suggestions.
What I really don't want to do is to individually initialize all 4 x 25
constants each time I call any of the 3 Functions, as these functions
are extensively used on the spreadsheet and this would slow down
operation significantly. And this really is an ugly, brute-force way
of doing things!
I have had these 3 routines using the old Macro language from Excel 4.0
days, but this is fairly ugly using two linked XL documents, and I want
to make the whole spreadsheet available to other people, including some
Windows users. Hence I thought I would try and update them to VBA.
So, please, please, suggestions as to how I set about this simple task.
Thanks,
Paul.