global Templates and autotext

D

Dragon

Hi. I am trying to write code to access autotext from a global template in
the Add-in list. I had tried both:

NormalTemplate.AutoTextEntries("Detention").Insert _
Where:=Selection.Range, RichText:=True

and

ActiveDocument.AttachedTemplate.AutoTextEntries("Detention").Insert _
Where:=Selection.Range, RichText:=True

but I get a 5941 error - object not found. I have proceeded the line with:

Set endff = ActiveDocument.FormFields(ActiveDocument.FormFields.Count)
endff.Select

to designate the last form field. The ActiveDocument command was working
fine when I was within the Template itself. Now that I am trying to access
the autotext from a different document, it isn't working.

I would be greatful for any assistanct.

Thanks.
 
T

Thomas Winter

Using the AttachedTemplate property isn't going to work, since your document
is not based on the template. To get the AutoTextEntries collection, you
need a Template object for your global add-in. I can't think of a way to get
that Template object except by actually opening the file. The AddIn object
doesn't give you any access to the Template object.

I actually tried out this scenario with the macro recorder, inserting a
piece of AutoText from a global add-in. The resulting macro code started out
with:

NormalTemplate.AutoTextEntries("Test").Insert......

If you actually run this code, you get an error! But of course, since my
AutoText is NOT in the Normal template, its in another add-in. I guess its
not surprising, but the Macro Recorder doesn't even know how to do this!

-Tom
 
C

Charles Kenyon

Hi,

The following should get you started.

Sub InsertATFromGlobal()
' Written by Charles Kyle Kenyon 20 December 2003
'
' Inserts AutoText Entry designated in sEntryName
Dim sTemplateFullName As String
Dim sEntryName As String
'
' Get name and path of global containing this code
'
sTemplateFullName = ThisDocument.FullName
sEntryName = "ATTN:" ' Entry name
Templates(sTemplateFullName).AutoTextEntries _
(sEntryName).Insert _
Where:=Selection.Range, RichText:=True
End Sub

This was run in Word 2003 but I think it should work back to Word 97. The
code is in the global and inserts the appropriate entry from that global.
Unfortunately it requires a separate macro for each AT entry. You could make
it a sub with a parameter of the AT entry name but that could still only be
called from another procedure in the global unless you reference your global
from your templates.

The macros could be put on a toolbar menu, but you don't need the macros to
do that. You can put AT entries directly on a custom menu without using any
code.

Hope this helps.
--

Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://addbalance.com/usersguide/index.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top