Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy AutoText Entries from Global Template to Other Templates

Status
Not open for further replies.

cheriberi

Technical User
May 27, 2003
60
US
Hi,

I have three AutoText entries that I need to copy from a global template to a number of other templates. I don't want to insert the AutoText entries into the text of my templates, just copy them into the AutoText list so they are available if needed. Is there a way to do this using VBA? Nothing I've tried has worked.

I want to put the macro to do this in the global template, which is in my Startup folder.

Thanks!

Cheryl
 
You need to insert the AutoText into a document and then create a new AutoText from whatever gets inserted, in the other template.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Oh, yikes!! Really? That's not a good thing! I was hoping I could somehow do it using Organizer and was just not doing it right.

Cheryl
 
Hi Cheryl,

it is possible - with a little trick...
:)

use this as framework:
Code:
Sub CopyAutoText()
Dim tpl As Template, doc As Document, othertpl As Template
Dim at As AutoTextEntry

Set tpl = ActiveDocument.AttachedTemplate
Set doc = Documents.Add("D:\testtemplate.dot")
Set othertpl = doc.AttachedTemplate
For Each at In tpl.AutoTextEntries
    doc.AttachedTemplate.AutoTextEntries.Add at, doc.Range
Next at
othertpl.Save
doc.Close
End Sub

Tested!
;-)

Cheers,
Andy

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
How does this macro work? I'm having a little trouble understanding it. If I am copying the AutoText entries from MySourceTemplate.dot to MyOtherTemplate.dot, how do those two files fit into this macro? They are both existing templates.

Cheryl
 
Oh, and I should specify that I only want to copy 3 specific AutoText entries to the other template. Would it be easier if I copied them to the Normal template first, and then run a macro to copy these 3 AT entries to my other template?
 
Hi Cheryl,

it doesn't really make a difference if you copy the entries to Normal.dot first.

Here's what the macro does:
1) I have created a template "globaltemplate.dot", and added three autotext entries to it.
2) I have created a new, empty template "testtamplate.dot" without any autotext entries.

3)I have created a new, empty document based on globaltemplate by just double clicking globaltemplate.dot, thus making globaltemplate the attached template of the new document.
==>
Code:
Set tpl = ActiveDocument.AttachedTemplate

As you cannot access templates directly the way you can access documents, I let the macro create a new document based on the other template:
==>
Code:
Set doc = Documents.Add("D:\testtemplate.dot")
Now I can access the other template
==>
Code:
Set othertpl = doc.AttachedTemplate

This code would copy ALL autotext entries of the globaltemplate to the other template:
Code:
For Each at In tpl.AutoTextEntries
    doc.AttachedTemplate.AutoTextEntries.Add at, doc.Range
Next at

As you only want three specific autotext entries (I hope they have names), you should be able to achieve this like this instead of using a for each loop:
Code:
doc.AttachedTemplate.AutoTextEntries.Add [b]tpl.AutoTextEntries("whatever 1")[/b], doc.Range
doc.AttachedTemplate.AutoTextEntries.Add [b]tpl.AutoTextEntries("whatever 2")[/b], doc.Range
doc.AttachedTemplate.AutoTextEntries.Add [b]tpl.AutoTextEntries("whatever 3")[/b], doc.Range

Now I have to SAVE these changes made to the template underlying, and then close the parent document:
Code:
othertpl.Save
doc.Close

Does this help?

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
I tried the code above and couldn't get it to work. Which template is open (the active document)? Why would a new document need to be created from the empty template (the TestTemplate.dot)?

I got an error on the code that tries to add the autotext entries. I can't figure out what I am doing wrong.

Cheryl
 
I tried this again and this time the AutoText entries did copy over. Is it possible to put the AutoText entries into the active document instead of creating a new document and putting them there?

Cheryl
 
Hi Cheryl,

AutoText entries are always contained in the template the document is based on.
So no, you cannot store AutoText entries in a document.

MiS

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Sorry, the active document was actually a template that I wanted to somehow copy into.

What I am trying to do is copy three new AutoText entries into about 200 existing templates. I'm hoping that there's a way to do this by macro so I don't have to copy these AutoText entries over manually one template at a time.

Cheryl
 
Hi,

I followed this thread as my problem is different: I have 299 autotexts in 20 categories which I would like to administrate properly. I haven't found a solution yet.

In Word97 to 2003 I found: if you copy autotexts via the organizer dialogue they lose their categories and every single autotext gets its own category with the same name like the autotext. But I found also: this does not happen if styles with the names of the categories to copy exist in the target document. If haven't tried copying autotexts via macro yet but I hope posting this might help.

Another thought occured to me: why are you trying to copy only three autotexts in 200 templates? I have a notion that this might be a way to transport information into a template (like company name, postcode ...) rather than a helping tool for someone actually writing in documents basing on the target template. If so, couldn't you use a link to a file with the information which is intended to be copied via the three autotexts?

Regards,

Markus
 
I don't know if it's possible to bring in the AutoText info via a separate template or how it would be done via a macro since I would need to automate the process.

Also, I need to somehow copy a Toolbar from one template to all 200 of the other templates and haven't been able to figure that out either.
 
Also, I need to somehow copy a Toolbar from one template to all 200 of the other templates and haven't been able to figure that out either.
Wait a sec... Now it's getting weird!
Toolbar?
You also want to copy macros over?
Why??
Why don't you simply add the global template to your add-ins then? Possibly in Startup folder so it automatically loads.
I am suspecting you are trying to solve problem that actually IS none!

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Hi Cheryl,

after the last three posts I am inclined to assume that

a) you have devised a system of templates to assist the users in your company and

b) you need to update information in these templates
alpha)* via autotexts - presumably intended to deliver new strings
beta) via toolbars - presumably intended to deliver new VBA procedures wrapped in the menu users are accustomed to.

Am I right? If so, then there will be help throughout this forum. I keep learning every single day.

Regards,

Markus
_____________
* Unfortunately I do not know how to show greek characters on this site.
 
Exactly right! These are templates that are specific to a group and I need to make it as simple as possible to run them since the members of the group change. By putting the AutoText and Toolbar in the templates themselves, it doesn't matter who uses them, they will work for everyone. No one needs to add anything to the Startup folder.

Since I haven't yet figured out how to copy either the AutoText or the Toolbar via macro, I may be manually copying them over in the next week or so. Not a fun prospect. I'm hoping someone here can help me figure out how to do it using VBA.

Cheryl
 
I think you should rethink how you are going about this.

200 templates seems a bit over-the-top. As you have discovered, it becomes a maintainence problem.

Why, if you want 200 templates to have the same AutoText, have one template that has them, and use that one?

Gerry
 
That would work for me too. But I'd still be at a loss as to how to get the AutoText from that one template into another existing template.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top