[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1191
  • Last Modified:

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?
0
DocZeuss
Asked:
DocZeuss
  • 10
  • 8
1 Solution
 
DreamboatCommented:
0
 
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?
0
 
DreamboatCommented:
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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?
0
 
DreamboatCommented:
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
 
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.
0
 
DreamboatCommented:
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
 
DreamboatCommented:
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
 
DocZeussAuthor Commented:
Follow-up: the code works fine in Word XP.  SO this may be a Word 2k issue.
0
 
DreamboatCommented:
Did you check your 2k security settings...
0
 
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?
0
 
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!
0
 
DreamboatCommented:
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
 
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..."?
0
 
DreamboatCommented:
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
 
DreamboatCommented:
Oh, and I'll take chocolate buttercream, please.
0
 
DocZeussAuthor Commented:
This worked nicely.  Thanks for all your help!
0
 
DreamboatCommented:
sure thing, doc!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 10
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now