Group: microsoft.public.word.vba.general
From: "fumei via OfficeKB.com"
Date: Wednesday, April 09, 2008 2:46 PM
Subject: Re: Sharing Arrays Between Modules

You can use Redim (in a userform module) on an array declared Public in a
standard module.

Declaring it Public in a standard module makes it Public anywhere.

I have never figured out the logic why you can not declare Public arrays in
object modules. Other than the (very real) possibility that the userform is
unloaded. In which case, it can hardly be Public.

It is that darn Scope thing again.

NZ VBA Developer wrote:
>Jonathan,
>
>I did initially try declaring the array as Public in the UserForm module. I
>did this because I knew that, as you stated, Public variables functioned like
>properties of the UserForm and thus became easily accessible in the rest of
>the project. However, I got a compile error stating that arrays (amongst
>others - constants, fixed-length strings, etc.) are not allowed as Public
>members of object modules, which instigated this post.
>
>The good news is I've run a quick test just now and have discovered that an
>array *can* be declared as Public in an ordinary module; apparently the
>limitation on the declaration of Public arrays is only around object modules,
>such as UserForms. This is a great help. Now I just need to see if I can
>manipulate the array in the UserForm module as it needs to be dynamic and
>thus support the use of a ReDim.
>
>So in summary, while your first suggestion doesn't work, your second one
>does and has got me pointed in the right direction. Thanks for your
>assistance!
>
>> There are two ways round this.
>>
>[quoted text clipped - 6 lines]
>> Alternatively, you can declare the array as Public in any ordinary module.
>> It is then a simple public array accessible from any routine in any module.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200804/1

Safety Articles | Usenet Groups | Usenet News | Bluegrass