Re: Preventing macro from copying over from template to document

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"chris_huh" <chris.huh@xxxxxxxxx> wrote in message
news:57e4b90e-bf01-4ff4-8b9b-156b44e9d778@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On 26 Jun, 14:00, "Jonathan West" <jw...@xxxxxxxx> wrote:
<<Ah yes i see. In the projects box (top left) it lists the template and
the document. The ThisDocument thing under the document is blank. I
think you can see what i'm going to ask next. Is there a way to remove
this template reference so when you open that document there is no
Enable Macros request?>>

Yes. Add the following line to your macro at some suitable point.

ActiveDocument.AttachedTemplate = NormalTemplate

Then the document will be attached to Normal.dot, not to the template.

Alternatively, digitally sign your template so that it is regarded as
being
trusted, and the warning will no longer appear. If it is just for local
use,
you can create your own certificate. On the Windows Start menu, go to
Microsoft Office, then Microsoft Office Tools. In that submenu you should
see "Digital Certificate for VBA Projects". Click that and follow the
instructions.

<<I also changed that code for the saving. That now allows you to change
the location and name (great, thanks) but is there a way for that to
happen when you click Save, rather than close. I guess you woudl take
that bit out of the Document_Close sub, but what would i put it in?>>

Create a new module, and create a routine in it called FileSave Put the
code
I provided into that routine.

--
Regards
Jonathan West - Word MVPwww.intelligentdocuments.co.uk
Please reply to the newsgroup

Thats got rid of the Enable Macros dialog, thanks.

I am not too proficient with macros and vba. Is a routine different to
a sub, etc. How would i do that. I made a new module (Module1 under
the Modules heading) and then put in:

Sub FileSave()

Sunday = Format(WeekStart() + 7, "d")
Saturday = Format(WeekStart() + 13, "d MMM yy")

FileTitle = Sunday & " - " & Saturday & ".doc"

With Dialogs(wdDialogFileSaveAs)
.Name = "J:\Editorial\Magellan\Sickness Absence\Afghan\" &
FileTitle
.Show
End With

End Sub

That didn't do anything.

What is should do (and as far as I can see, you have done it right) is
display the Save dialog predefined when you press Ctrl-S. However, it won't
do that if you have already unlinked the document from the template, as the
template containg the macro is no longer attached to the document!

Therefore, perhaps you need to move the AttachedTemplate command from where
it is and add it to the start of the FileSave macro, so that the template
remains attached until you first save the the document.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


.



Relevant Pages

  • Re: Advanced MS Word Template Design Question: Image swap
    ... The only difference between the autotext TEXT and the autotext IMAGE ... modify the template in Mac to get it to align properly. ... > Sub CheckIt() ... > names of the macros and AutoText entries the same, ...
    (microsoft.public.word.docmanagement)
  • Re: Saving a doc that was created by a template
    ... First a little background on the "mechanics" of Word macros. ... Word recognizes the following names as automatic macros, ... UserForm in your template, you'll probably see a procedure called something ... "Open" event of the document (Private Sub Document_Open). ...
    (microsoft.public.word.vba.general)
  • Re: Catching document save event
    ... template the same name as the built-in Word commands. ... In the 'Macros in' dropdown, ... From the list, select 'FileSave'. ...
    (microsoft.public.word.vba.general)
  • Re: Running multiple macros
    ... > turned into a template at the end of this project. ... Both of my VBE macros ... > Sub ParaFormat() ... >> Please respond to the Newsgroup for the benefit of others who may be ...
    (microsoft.public.word.vba.general)
  • Re: Shift enter mapping
    ... These macros were added to a template other than Normal.dot and I ... > Sub AutoNew() ... > CustomizationContext = ActiveDocument.AttachedTemplate ...
    (microsoft.public.word.vba.general)