Insert autotext from globaltemplate

C

camilla

I have 25 templates and they all has he same autotext. Now I have moved all
autotext to one global template, adress.dot, but I cant insert it in to the
document based on the old templates.
The old code was:

ActiveDocument.AttachedTemplate.AutoTextEntries("dn_Adr_Lul").Insert
Selection.Range, True

I hope someone understand what I mean and can help me with a solution
 
R

Rick Stebbins

Try using the Templates collection, for example:

Word.Templates(5).AutoTextEntries("dn_Adr_Lul").Insert
selection.Range, true


For some reason, it only worked for me when I specified
the Index number of the global template. So, I needed to
write a routine that looks up the Index first, rather than
just specifying the global template's name.
 
C

camilla

Thanks, it´s exactly what I need. If you write a routine, can you please
notify me.

Regards
 
R

Rick Stebbins

Here is the function. Your procedure will need error
handling in case the specified addin is not loaded or the
autotext name is invalid...


Public Function GlobalTemplate(Optional ByVal
TemplateAddinName As String = "Normal.dot") As
Word.Template
Dim n As Long

With Word.Templates
For n = 1 To .Count
If InStr(1, .Item(n).Name, TemplateAddinName,
vbTextCompare) Then
Set GlobalTemplate = .Item(n)
Exit For
End If
Next n
End With

End Function


Sub YourProcedure()
On Error Resume Next
GlobalTemplate("adress.dot").AutoTextEntries
("dn_Adr_Lul").Insert Selection.Range, True
End Sub
 

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