To transfer the code and detach the template, you could use a macro like:
Code:
Sub CopyCodeModule()
Dim StrModule As String
StrModule = "MyModule"
' Delete any old copies of the module
On Error Resume Next
Kill (StrModule & ".bas")
On Error GoTo 0
' Export Module
ActiveDocument.AttachedTemplate.VBProject.VBComponents(StrModule).Export (StrModule & ".bas")
' Import Module
Application.VBE.ActiveVBProject.VBComponents.Import (StrModule & ".bas")
' Delete the module copy
Kill (StrModule & ".bas")
ActiveDocument.AttachedTemplate.Name = ""
End Sub
where the name of the module to be transferred is 'MyModule'.
Note: To use the above code, you need to set a reference to Microsoft Visual Basic For Applications Extensibility and grant access to VBA object model (see
http://support.microsoft.com/kb/282830)