Use Word VBA to Insert Multiple INCLUDETEXT Fields
Question details
The user needs to insert separate INCLUDETEXT fields for multiple text files using Word VBA.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A VBA macro loops through text files and inserts a field for each file.
- Observed behavior
- Separate field and TypeText statements can leave INCLUDETEXT fields nested or improperly closed.
Open the document in a desktop version of Word that supports VBA, and confirm that the source text files are accessible. Enable the Developer tab if it is hidden, and run macros only from trusted sources.
Create each INCLUDETEXT field with a single Fields.Add call
Use a complete field instruction in each call so Word creates each field independently.
Pass the full INCLUDETEXT instruction to Fields.Add instead of inserting the field and typing its code in separate statements. Quote each source path so paths containing spaces are handled correctly.
In Word, select Developer > Visual Basic, then choose Insert > Module.
Paste this example into the module, then replace the sample paths with your text-file paths: Sub InsertIncludeTextFields() Dim filePath As Variant Dim fld As Field Dim files As Variant files = Array("C:\Data Files\one.txt", "C:\Data Files\two.txt") For Each filePath In files Set fld = Selection.Fields.Add( _ Range:=Selection.Range, _ Type:=wdFieldEmpty, _ Text:="INCLUDETEXT " & Chr(34) & CStr(filePath) & Chr(34), _ PreserveFormatting:=False) fld.Update Selection.SetRange Start:=fld.Result.End + 1, End:=fld.Result.End + 1 Selection.TypeParagraph Next filePath End Sub
Place the cursor where the fields should begin, then select Developer > Macros, choose InsertIncludeTextFields, and select Run. To inspect a field, right-click it and choose Toggle Field Codes.

Edit Word documents with WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Word documents. Its Word format support helps make migration straightforward, though it does not fix Word VBA field-creation behavior.

Frequently Asked Questions
Why are my INCLUDETEXT fields nested?
Typing a field instruction after creating a field can leave the insertion point inside an existing field. Pass the complete instruction to Selection.Fields.Add and move the selection past the completed field before inserting the next one.
How do I handle file paths with spaces?
Surround the path in the field instruction with quotation marks. In VBA, use Chr(34) before and after the path when building the Text argument.
How can I see the field code in Word?
Right-click the field and select Toggle Field Codes. You can then check the INCLUDETEXT instruction and its source path.
How do I refresh content from a source file?
Right-click the INCLUDETEXT field and select Update Field. The source file must be accessible at the path stored in the field.




