Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-21-2014, 01:56 AM
Cristin7 Cristin7 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
Novice
How to save a macro in a document generated with a word model?
 
Join Date: Mar 2014
Posts: 5
Cristin7 is on a distinguished road
Question How to save a macro in a document generated with a word model?

Hello,

I need help. I have created a word document model and I'd like to save in the document generated opening the model a macro that is in the model, how can I do?
I need the automatic saving of the macro in all the document generated by using the model.
I need the macro available for everyone opening the generate document on different PC.

Thank you!

Last edited by Cristin7; 03-21-2014 at 03:08 AM.
Reply With Quote
  #2  
Old 03-23-2014, 07:53 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: 21,962
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

Macros in document templates are automatically available to any document created from those templates, provided the template is available. In a corporate environment, that ordinarily only entails ensuring the template is stored in a folder accessible to all who need access to it.

The only time you might need to insert the macro into the resulting document is if it is going to be used in situations where the template isn't available. But then you should also be look at detaching the document from the template so Word doesn't waste time trying to access it when the network isn't available.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-24-2014, 04:34 AM
Cristin7 Cristin7 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
Novice
How to save a macro in a document generated with a word model?
 
Join Date: Mar 2014
Posts: 5
Cristin7 is on a distinguished road
Default

Thank you, your ansewer is very clear.

In the case in which I want to use the document in situations where the template isn't available, how can I insert the macro in the document in autonoumous way?
Another question: How can I detach the document from the template so Word doesn't waste time trying to access it when the network isn't available?

Thank you

Chiara
Reply With Quote
  #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: 21,962
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
  #5  
Old 03-25-2014, 03:25 AM
Cristin7 Cristin7 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
Novice
How to save a macro in a document generated with a word model?
 
Join Date: Mar 2014
Posts: 5
Cristin7 is on a distinguished road
Default

Thank you very much it workes correctly.
I changed only:
Application.VBE.ActiveVBProject.VBComponents.Impor t (StrModule & ".bas")

with the following:
ActiveDocument.VBProject.VBComponents.Import (StrModule & ".bas")

and I changed :
ActiveDocument.AttachedTemplate.Name = ""

with the following:
ActiveDocument.AttachedTemplate = ""


Thank you

Chiara
Reply With Quote
Reply

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 01:35 AM.


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