PDA

View Full Version : Solved: AutoText making me CRAZY!!



dchapin
07-01-2008, 05:16 PM
I have a document template which I load by storing it in the startup directory. This template contains autotext entries.... pretty simple so far... I am trying to add code to insert one of the autotext entries into the active document.

The code i hav so far is:

ActiveDocument.AttachedTemplate.AutoTextEntries("Prompt For Typist").Insert Where:=Selection.Range

which everything tells me should work. When I run word and click my button that should insert the autotext (which, by the way DOES exist), I get a Runtime error 5941: The requested member of the collection does not exist.

I just cannot see how to do this, or what my problem is....

Please help.... DC

dchapin
07-01-2008, 06:11 PM
Just found this in a response post by fumei... Answers question


Sub UseGlobalAT()
Dim aTemplate As Template
Dim myTemplate As Template
For Each aTemplate In Templates
If aTemplate = "CherylGlobal.dot" Then
Set myTemplate = aTemplate
myTemplate.AutoTextEntries("My AutoText"). _
Insert Where:=Selection.Range, RichText:=True
Exit For
End If
Next
End Sub

fumei
07-06-2008, 03:33 AM
Just to clarify something:

"I have a document template which I load by storing it in the startup directory. "

A template (.dot file) in Startup is not a document template, per se. It is a global template, that is, it is essentially designed as a code container.

The reason my code works is that a template object is created, and used. Template objects DO allow access to their autotext. Global templates do not. Not unless they are identified as a document template.

By the way, this is also true for Styles. Global templates, as themselves, are NOT Style containers.

fumei
07-06-2008, 03:36 AM
Or to put it another way...

A template file in Startup is never the Attached Template for any document. Not unless you use it as such by cloning it as a document. Or explicitly attaching it. having it in startup does NOT attach it to any document. Its code is parsed and made available to the application, i.e. Word itself.