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?
DocZeussAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anne TroyEast Coast ManagerCommented:
DocZeussAuthor Commented:
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/Applications/MS_Office/Word/Q_20707834.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?
Anne TroyEast Coast ManagerCommented:
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.
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

DocZeussAuthor Commented:
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?
Anne TroyEast Coast ManagerCommented:
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.
DocZeussAuthor Commented:
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.
Anne TroyEast Coast ManagerCommented:
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...
Anne TroyEast Coast ManagerCommented:
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)?
DocZeussAuthor Commented:
Follow-up: the code works fine in Word XP.  SO this may be a Word 2k issue.
Anne TroyEast Coast ManagerCommented:
Did you check your 2k security settings...
DocZeussAuthor Commented:
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?
DocZeussAuthor Commented:
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!
Anne TroyEast Coast ManagerCommented:
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.
DocZeussAuthor Commented:
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..."?
Anne TroyEast Coast ManagerCommented:
Hmmm...
Don't do it on save as, do it on close.

Open the VBE (Alt+F11)

Double-click ThisDocument on your TEMPLATE.
Choose the dropdowns in the code window for Document_Close

paste the code between the Sub/End sub that appears.

And I don't code. You might find some REAL interesting information in MY past questions!
smozgur helped me with this exact issue (the template asking to save changes) and some related issues in February of last year. Here's one:

http://www.experts-exchange.com/Applications/MS_Office/Q_20267391.html

So you see, I STOLE.
:)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anne TroyEast Coast ManagerCommented:
Oh, and I'll take chocolate buttercream, please.
DocZeussAuthor Commented:
This worked nicely.  Thanks for all your help!
Anne TroyEast Coast ManagerCommented:
sure thing, doc!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.