To programmatically add code to a Word document or template requires the basic process as for Excel, etc.:
1. Set a reference to Microsoft Visual Basic For Applications Extensibility.
2. Give trusted access to the VBE.
The Excel procedure below will add a new module named "NewModule" to ThisWorkbook:
Code:
Sub AddModule()
Dim VBComp As VBComponent
Set VBComp = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_StdModule)
VBComp.Name = "NewModule"
Application.Visible = True
End Sub
The Word equivalent is:
Code:
Sub AddModule()
Dim VBComp As VBComponent
Set VBComp = ThisDocument.VBProject.VBComponents.Add(vbext_ct_StdModule)
VBComp.Name = "NewModule"
Application.Visible = True
End Sub
If this isn't the kind of thing you need, you need to say what it is you do need.