View Single Post
 
Old 03-24-2014, 08:58 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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 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)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote