View Single Post
 
Old 11-06-2014, 01:52 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,366
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote