Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 03-24-2014, 08:58 PM
macropod's Avatar
macropod macropod is offline How to save a macro in a document generated with a word model? Windows 7 32bit How to save a macro in a document generated with a word model? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,512
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
 

Tags
macro problem



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I save a Word file with a macro for distribution? leemoreau Word VBA 3 10-04-2013 08:06 AM
How to save a macro in a document generated with a word model? Comparing with a model format qetuo Word 2 05-01-2013 11:23 PM
How to save a macro in a document generated with a word model? Macro to create new word doc and save the file using String found in the document VBNation Word VBA 2 02-08-2013 07:14 AM
Word ask to save template whenever i save a derived document jorbjo Word 3 10-04-2012 10:52 AM
How to save a macro in a document generated with a word model? NEED macro to save word doc as pdf socrates01 Word 3 07-11-2011 05:12 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft