You can do that by first exporting the code module from the template, then adding the following code to the template's 'This Document' module:
Code:
Private Sub Document_New()
Dim InFile As String
InFile = "C:\Users\Brien Wen\My Documents\Templates\CodeModule.bas"
If Dir(InFile) = "" Then Exit Sub
Application.VBE.ActiveVBProject.VBComponents.Import (InFile)
End Sub
Change the path & filename to match wherever you store the code module. If you need the solution to be portable, you can add code to do the export also (to, say the template's own folder) every time a new file is created and, after importing into the new document, delete the exported module.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.