Share a Dynamic Array Between Word VBA UserForms
Question details
Share a dynamic array between two Word VBA UserForms and read its values after the second form closes.

- Product
- Microsoft Word VBA
- Device & OS
- not provided
- Scenario
- One UserForm opens a second UserForm that fills a dynamic array and then closes.
- Observed behavior
- The first UserForm needs access to the values populated by the second UserForm.
Open the document in Word and make sure it is saved in a macro-enabled format, such as .docm. Open the VBA editor from Developer > Visual Basic, and identify the names of both UserForms and their buttons.
Declare the dynamic array in a standard VBA module
Use a public array when both UserForms need to access the same values within the document's VBA project.
A public variable in a standard module is accessible to both forms. A separate Boolean flag lets the first form check whether the second form actually supplied values.
In the VBA editor, select the document's project and choose Insert > Module. Add these declarations: Public MyArray() As String Public ArrayReady As Boolean
Open the second UserForm's code and add the following to the button that confirms its values. Replace the sample strings with the values collected by your form: Private Sub CommandButton1_Click() ReDim MyArray(0 To 1) MyArray(0) = "First value" MyArray(1) = "Second value" ArrayReady = True Unload Me End Sub
In the first UserForm's button code, show the second form modally, then check the flag before reading the array. Replace UserFormB and the button event name with your actual names: Private Sub CommandButton1_Click() ArrayReady = False UserFormB.Show vbModal If ArrayReady Then Debug.Print MyArray(0) Debug.Print MyArray(1) End If End Sub
Run the first UserForm from the VBA editor, open and confirm the second form, then check View > Immediate Window for the sample values. Adapt the array size and indexes to your data.

Edit Word Documents with WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Word documents. Its format compatibility helps you move everyday documents between office suites; it does not fix Word VBA UserForm code.

Frequently Asked Questions
Why should the array be declared in a standard module?
A Public array declared through Insert > Module is accessible to both UserForms in the same VBA project. An array declared in a UserForm module is tied to that form's scope or instance.
How do I know whether the second form supplied values?
Set a public Boolean flag to False before calling UserFormB.Show vbModal, and set it to True when the second form confirms its data. Check the flag before reading the array.
Can I share the array without using a public module variable?
Yes. You can expose a property on the first UserForm and have the second form assign a Variant array to it. Make sure the second form has a reference to the same first-form instance that will read the property.
Where can I see the values printed by Debug.Print?
In the VBA editor, choose View > Immediate Window. Run the first form, confirm the second form, and look for the printed array values there.




