Link to home
Start Free TrialLog in
Avatar of DocZeuss
DocZeuss

asked on

How do you set the AttachedTemplate = "" ?

We use a Word Template to automatically link to an Access database to create a mail merge document.  The problem that we’re having is that the Attached Template property links back to the original DOT file.  Every time we open a merged file based on the original template, the Access database is opened and the DOT file tries to create the auto-merge again.

Is there a way to automatically reset the property, AttachedTemplate = “Normal.dot” in the merged document?
Avatar of Anne Troy
Anne Troy
Flag of United States of America image

Avatar of DocZeuss
DocZeuss

ASKER

Dreamboat,

The code that you pointed me to doesn't seem to work in Word 2k.  I have also tried several other similar solutions:

http://beta.experts-exchange.com/questions/20707834/Remove-hidden-template-link-from-word-file.html

http://support.microsoft.com/default.aspx?kbid=830561

This should be easy, but I haven't worked with programming code since DOS Basic!

I couldn't find any specific help in MS Knowledgebase for Word 2000?  Any other suggestions?
Doesn't work? What occurs? Error messages?

You said:

>>Every time we open a merged file based on the original template, the Access database is opened and the DOT file tries to create the auto-merge again.

Are you sure you're not OPENING the DOT file? The code shouldn't be "copied over" to the merged document...

You should paste the code you're using now.
Let me be more precise:

1. We create a NEW Word file (Document1.doc) by double-clicking on "Template.DOT" which launches Access, prompts for a Job Number, and establishes mail merge links to our "data.mdb".

2. From "Document1.DOC" (created by the template file), we mail merge to a new file: "Form Letters1.doc".  We then save this file as "JobNumber.doc"

3. "JobNumber.doc" contains an AttachedDocument property that points to "Template.dot".  We want this link broken because every time you open "JobNumber.doc", the Template.DOT is opened, and then Access is launched again.

Is there a way to mail merge without creating a link back to the Template.dot?
Oh, I see.

In your code, after the mail merge is performed....

    With ActiveDocument
        .AttachedTemplate = "C:\PathToNormalDot\Normal.dot"
    End With

Does that help?
I don't code.
I just steal and record.
The code that you reccomended is exactly the same as my first attempt - I used the record a macro feature...

Interestingly, the macro works - BUT - you have run it twice!  The first time I run it, it opens the Control Tool Box toolbar and toggles design mode ON (opens a second one-bottom toolbar with no name) and halts.  I figured that the record a macro feature was the problem!

So why then does this code not work?  Do you think it has anything to do with the Template.DOT being a read-only file?  Maybe it tries to save it and stops the macro when it fails?  I'll try changing it.

I even tried to record a macro that runs the code above twice - no luck.  

This should be easy, but alas, I am stumped.  Microsoft has some elaborate code to loop trhough files in a directory to reset the AttachedTemplate proerty in KB articles I posted.  Those don't work either.  It may be a Word 2K issue?

I would understand if you give up this one.  Thanks for all your help.
If you're getting design mode, you've got your macro security set to HIGH.
Open Word and go to Tools-Macro-Security and set it to low or medium.
THEN open your document.

Are you changing Template.dot?

What's the code you're using being CALLED from? Access or Word?

Sorry...I'm probably asking things you already answered...
Oh....you say you're using 2000. Do you have other versions on your PC? Are you sure you're calling 2000 instead of 97 (for instance)?
Follow-up: the code works fine in Word XP.  SO this may be a Word 2k issue.
Did you check your 2k security settings...
Duh.  I'm an idiot.  So much for the obvious.  Thanks for your help on this.  

One last Q, if I may be so bold: is there a way to make this code run automatically during the merge process?
Also, because the Template.DOT is read-only, Word prompts the user to save chnages to it.  Any way to include a "no" response to this dialog box automatically in the code?

I need to make this invisble to my users.  Lowering macro security worries me too.  I may look at setting trusted macro sources...

If any Microsoft Word programmers are reviewing this, please add some functinality to allow the user to change the Template Path when creating mail merge documents!!!!  Argh!
If you're in Word code, the line is something like this:

ActiveDocument.AttachedTemplate.Saved = True

If you do that, it thinks it's already saved and doesn't ask.
It does NOT save it.
And you say you don't know how to code!  Nice job.  That worked.  Here's the final code:

    ActiveDocument.AttachedTemplate.Saved = True
   
    With ActiveDocument
        .UpdateStylesOnOpen = False
        .AttachedTemplate = ""
    End With
   
The result is that it defualts to the user's normal.dot

Now for the icing on the cake, how do you make it run automatically?  Or even better, when the user does a "save as..."?
ASKER CERTIFIED SOLUTION
Avatar of Anne Troy
Anne Troy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, and I'll take chocolate buttercream, please.
This worked nicely.  Thanks for all your help!
sure thing, doc!