Group: microsoft.public.word.vba.general
From: =?Utf-8?B?TlogVkJBIERldmVsb3Blcg==?=
Date: Tuesday, April 08, 2008 4:25 PM
Subject: Re: Sharing Arrays Between Modules

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!

--
Cheers!
The Kiwi Koder


"Jonathan West" wrote:

>
>
> There are two ways round this.
>
> Arrays and variables in a UserForm can be public. Declare them using the
> Public keyword before the first Sub or Function in the code module of the
> UserForm. To the outside world, Public variables in a UserForm (or in a
> Class module) appear to be public properties of the form, and can be
> accessed in just the same way as any of the other properties of the form.
>
> 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.
>
>
> --
> Regards
> Jonathan West - Word MVP
> www.intelligentdocuments.co.uk
> Please reply to the newsgroup
>
>
>