![]() |
|
#1
|
|||
|
|||
![]()
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. |
#2
|
||||
|
||||
![]()
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] |
#3
|
|||
|
|||
![]()
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 |
#4
|
||||
|
||||
![]()
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 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] |
#5
|
|||
|
|||
![]()
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 |
![]() |
Tags |
macro problem |
|
![]() |
||||
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 |
![]() |
qetuo | Word | 2 | 05-01-2013 11:23 PM |
![]() |
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 |
![]() |
socrates01 | Word | 3 | 07-11-2011 05:12 AM |