Check for AutoText in Template

L

Liz

Hi -
I am creating a global template in 2003 to be placed in a user's startup
directory.

I currently have a macro that successfully copies 4 different autotext items
from the Global template in the startup directory to the currently attached
template (main attached template found within the templates directory).

However, I would like this macro to only execute after it looks for the
autotext in the attached template and cannot find it. If it does not find
this autotext in the attached template, then I would like the macro to run
from my Global template that copies over the autotext.

Would you be able to help me with the vb code needed to check for a named
autotext item in the attached template?

Also - can I get a common code to work in both 2003 and 2007? I have users
in 2003 and 2007.

My current code is below:

'Define AutoText to be copied
sName1 = "AutoText for Update"

Application.OrganizerCopy _
Source:= Application.StartupPath & sGlobalFile, _
Destination:=ActiveDocument.AttachedTemplate, _
Name:=sName1, Object:=wdOrganizerObjectAutoText


Thanks so much,
Liz
 
D

DaveLett

Hi Liz,
You can try the following:

Dim vGlobal As Variant
Dim iGlobal As Integer
Dim iAttached As Integer
Dim bFound As Boolean

vGlobal = Array("AutoText1", "AutoText2", "AutoText3", "AutoText4")

For iGlobal = LBound(vGlobal) To UBound(vGlobal)
bFound = False
For iAttached = 1 To ActiveDocument.AttachedTemplate.AutoTextEntries.Count
If vGlobal(iGlobal) =
ActiveDocument.AttachedTemplate.AutoTextEntries(iAttached).Name Then
bFound = True
Exit For
End If
Next iAttached
If bFound = False Then
Application.OrganizerCopy _
Source:=Application.StartupPath & sGlobalFile, _
Destination:=ActiveDocument.AttachedTemplate, _
Name:=vGlobal(iGlobal), Object:=wdOrganizerObjectAutoText
End If
Next iGlobal

HTH,
Dave
 

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