Accesing Autotext

P

PPL

Hi,
I'm having dificulty finding a VBA command or script that will let me access
an Auto text entry in a template that is NOT attached to the current
document. Is it possible to do this?

TIA

Philip
 
J

Jonathan West

PPL said:
Hi,
I'm having dificulty finding a VBA command or script that will let me
access an Auto text entry in a template that is NOT attached to the
current document. Is it possible to do this?

yes, if the template is open as an add-in. All add-ins are members of the
Templates collection, and you can extract Autotext from any template that is
a member of the Templates collection
 
G

Greg Maxey

Phillip,

Yes it is possible if the template is identified as a global template/AddIn.

Let's say you have a template named Test.dot with an AutoText entry defined
as "gofish"

In my case templates are stored in "E:\My Documents\Word\Template so yo will
need to change the code accordingly:

Sub ScratchMacro()
Dim oAI As AddIn
Dim oRng As Range
Dim oTemplate As Template
Dim bAvailable As Boolean
Set oRng = Selection.Range
bAvailable = False
'Lets say your Addin is called "Test.Dot"
'Determine if the template is available as an AddIn
For Each oAI In AddIns
If oAI.Name = "Test.dot" Then
bAvailable = True
'Load it if not already loaded
If oAI.Installed = False Then oAI.Installed = True
Exit For
End If
Next
'If not available then add it to the AddIn collection
If Not bAvailable Then
AddIns.Add FileName:="E:\My Documents\Word\Templates\Test.dot",
Install:=True
End If
Set oTemplate = Templates("E:\My Documents\Word\Templates\Test.dot")
oRng.InsertAfter oTemplate.AutoTextEntries("gofish")
End Sub

I am not sure if this is a "good" way or not ;-)
 

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