Solved

How do you set the AttachedTemplate = "" ?

Posted on 2003-11-18
18
1,182 Views
Last Modified: 2007-12-19
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?
0
Comment
Question by:DocZeuss
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 8
18 Comments
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9773509
0
 

Author Comment

by:DocZeuss
ID: 9780541
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?
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9780608
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.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:DocZeuss
ID: 9783672
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?
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9783823
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.
0
 

Author Comment

by:DocZeuss
ID: 9788503
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.
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9788585
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...
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9788589
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)?
0
 

Author Comment

by:DocZeuss
ID: 9788603
Follow-up: the code works fine in Word XP.  SO this may be a Word 2k issue.
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9788631
Did you check your 2k security settings...
0
 

Author Comment

by:DocZeuss
ID: 9788741
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?
0
 

Author Comment

by:DocZeuss
ID: 9788784
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!
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9788850
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.
0
 

Author Comment

by:DocZeuss
ID: 9791014
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..."?
0
 
LVL 22

Accepted Solution

by:
Dreamboat earned 125 total points
ID: 9792102
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.
:)
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9792104
Oh, and I'll take chocolate buttercream, please.
0
 

Author Comment

by:DocZeuss
ID: 9795079
This worked nicely.  Thanks for all your help!
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9796474
sure thing, doc!
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question