VBA & Macro Problems

Share a Dynamic Array Between Word VBA UserForms

Anum MushtaqAnum Mushtaq Nov 20, 2026 868 views

Question details

Share a dynamic array between two Word VBA UserForms and read its values after the second form closes.

Share a Dynamic Array Between Word VBA UserForms
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.
Before you start

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.

Solution 1Recommended

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.

1
Add a standard module

In the VBA editor, select the document's project and choose Insert > Module. Add these declarations: Public MyArray() As String Public ArrayReady As Boolean

2
Fill the array in the second form

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

3
Open the second form and read its values

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

4
Test the forms

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.

Declare the dynamic array in a standard VBA module
Handle cancellation: If the second form closes without confirming, ArrayReady remains False and the first form skips reading the array. Add your own cancellation message or other handling if needed.
Free Microsoft Office alternative

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.

Open and edit Microsoft Word DOC and DOCX filesUse a familiar document-editing interface for easier migrationWork with documents in a lightweight office suiteKeep Word for VBA UserForm workflows that require Microsoft Word
microsoft office alternative - wps office

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.