VBA & Macro Problems

Insert Word Appendices with VBA UserForm Checkboxes

Anum MushtaqAnum Mushtaq Nov 20, 2026 870 views

Question details

Insert selected appendix files at the end of a Word document using checkboxes on a VBA UserForm.

Insert Word Appendices with VBA UserForm Checkboxes
Product
Microsoft Word
Device & OS
not provided
Scenario
A UserForm lets the user choose which appendix files to add to a document.
Observed behavior
Appendices may be inserted at the beginning or inside an unintended table if the insertion range or checkbox condition is incorrect.
Before you start

Check the checkbox names and the full paths of the appendix files you want to insert. Make sure the document has an editable final paragraph outside any table.

Solution 1Recommended

Insert checked appendix files at the document end

Use this approach to test each checkbox explicitly and insert its mapped file at the end of the active document.

The example maps CheckBox1 and CheckBox2 to two files. Update the names and paths to match your UserForm; add more Select Case entries for additional appendices.

Files are inserted in the order in which the UserForm controls are visited, not necessarily in checkbox-number order. If a specific order is required, process the checkboxes explicitly in that order.

1
Check the document end

In Word, go to the end of the document and confirm that the final insertion point is in a paragraph outside any table.

2
Open the UserForm code

Open Developer > Visual Basic, select your UserForm, and double-click its insert button to open the button's Click event.

3
Add the insertion code

Replace the button's Click event with the following example, changing CommandButton1 and the file paths as needed: Private Sub CommandButton1_Click() Dim aCtl As Control Dim sDocName As String For Each aCtl In Me.Controls If TypeName(aCtl) = "CheckBox" Then sDocName = "" Select Case aCtl.Name Case "CheckBox1" sDocName = "C:\Appendices\Appendix1.docx" Case "CheckBox2" sDocName = "C:\Appendices\Appendix2.docx" End Select If (aCtl.Name Like "CheckBox#*") And (sDocName <> "") And (aCtl.Value = True) Then If Dir(sDocName) <> "" Then ActiveDocument.Range.Characters.Last.InsertFile FileName:=sDocName Else MsgBox "File not found: " & sDocName End If End If End If Next aCtl End Sub

4
Test the selections

Run the UserForm, select one or more checkboxes, and click the insert button. Check the end of the active document to confirm that only the selected files were added.

Insert checked appendix files at the document end
Checkbox naming: The Like pattern CheckBox#* expects a digit after CheckBox, as in CheckBox1. Change the pattern if your controls use different names.
Free Microsoft Office alternative

Work with Word documents and appendices in WPS Writer

WPS Office is a free, lightweight Office alternative with a familiar interface for working with documents and their appendices. Its Word format support helps you move existing files into WPS Writer; it does not fix Microsoft Word UserForm or VBA errors.

Open and edit documents containing appendices in WPS WriterCompatible with Microsoft Word DOC and DOCX formatsFamiliar interface for a smoother transition from Microsoft OfficeFree and lightweight for everyday document work
microsoft office alternative - wps office

Frequently Asked Questions

How do I insert an appendix at the end instead of the beginning?

Use ActiveDocument.Range.Characters.Last.InsertFile with the appendix file path. Before running the macro, check that the document ends with an editable paragraph outside any table.

How can I make sure only checked boxes insert files?

In the UserForm button's Click event, test the checkbox value explicitly with aCtl.Value = True, along with the control name and a nonempty file path.

Do I need a bookmark to insert an appendix at the end?

No. The document's last-character range can be used with InsertFile, so a Schedules bookmark is not required for end-of-document insertion.

Where can I check the Microsoft Forms library?

In Word's Visual Basic Editor, open Tools > References. If the project requires Microsoft Forms 2.0 Object Library, check that it is available and that no required reference is marked MISSING.