Insert AutoText Entry from Global template via Macro

T

Tsu Dho Nimh

WORD claims: "A collection of AutoCorrectEntry objects that represent all the AutoCorrect entries available to Word. The AutoCorrectEntries collection includes all the entries in the AutoCorrect dialog box (Tools menu).

Well, although I can see and manually insert autotexts from the attached and the loaded global templates, I can't insert them by name from a macro if they are in the global template. This puts a serious dent in our plan to use global templates as storage for autotexts ... any solutions?
 
J

JGM

Hi Tsu Dho,

I think you are confusing two different things.
First of all, I have to make an assumption because you were not very clear
on what you are trying to achieve. I assume that you are trying to insert in
an AUTOTEXT entry at the cursor in the active document.

So, autocorrect entries are those you set up so that if you type, for
example, "laed" Word will automatically change it to "lead". As such, it is
not something you can insert in a document at the cursor. But you can
enumerate them in VBA and modify them...

Next, you are talking about autotext. Now, this is something you can insert
at the cursor from VBA.

For example, from the Word help:

Selection.Collapse Direction:=wdCollapseEnd
NormalTemplate.AutoTextEntries("TheWorld").Insert _
Where:=Selection.Range, RichText:=True

Using ", RichText:=True" is vey important if you want to preserve the
formatting that was used to create the autotext.

or, if you have a template that contains the Autotext (not necessarily the
one used to create the current document), you may want to play around with
something like:

Templates("D:\MyPath\MyGlobalTemplate.dot").AutoTextEntries("Test").Insert _
Where:=Selection.Range, RichText:=True

I hope that I managed to make sense of that topic for you!

Cheers!
--
_______________________________________
Jean-Guy Marcil
(e-mail address removed)

Tsu Dho Nimh said:
WORD claims: "A collection of AutoCorrectEntry objects that represent all
the AutoCorrect entries available to Word. The AutoCorrectEntries collection
includes all the entries in the AutoCorrect dialog box (Tools menu)."
Well, although I can see and manually insert autotexts from the attached
and the loaded global templates, I can't insert them by name from a macro if
they are in the global template. This puts a serious dent in our plan to
use global templates as storage for autotexts ... any solutions?
 
W

Word Heretic

G'day Tsu Dho Nimh <[email protected]>,

templates(n).auto....



WORD claims: "A collection of AutoCorrectEntry objects that represent all the AutoCorrect entries available to Word. The AutoCorrectEntries collection includes all the entries in the AutoCorrect dialog box (Tools menu)."

Well, although I can see and manually insert autotexts from the attached and the loaded global templates, I can't insert them by name from a macro if they are in the global template. This puts a serious dent in our plan to use global templates as storage for autotexts ... any solutions?

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
wordheretic.com

Replies offlist may require payment.
 
L

Laura Townsend

Hi,

I too got the impression from MS Word VBA help that if the autotext was
available from a global template, I could insert it as you described. But
apparently it needs the path and name of the specific template if it's not
the attached template.

Since the start up directory path can vary from machine to machine, this is
the sub-routine I've been using to accomplish this. When I call this
procedure I pass the autotext entry name (theEntry) and the name of the
bookmark (BookmarkName) that's in the doucment where I want to insert it.
The procedure also makes sure the bookmark exists in the document before
attempting to execute. I have a constant named sStartUp that contains the
name of the global template that contains the auto text.


Private Sub InsertTheAutoText(theEntry As String, BookmarkName As String)
Dim sTemplate As String

If ThisDocument.Bookmarks.Exists(BookmarkName) Then
sTemplate = Application.StartupPath
If Right(sTemplate, 1) <> Application.PathSeparator Then
sTemplate = sTemplate & Application.PathSeparator
End If
sTemplate = sTemplate & sStartUp
ActiveDocument.Bookmarks(BookmarkName).Select
Templates(sTemplate).AutoTextEntries(theEntry).Insert _
where:=Selection.Range, RichText:=True

End If
End Sub

Good Luck,
Laura


Tsu Dho Nimh said:
WORD claims: "A collection of AutoCorrectEntry objects that represent all
the AutoCorrect entries available to Word. The AutoCorrectEntries collection
includes all the entries in the AutoCorrect dialog box (Tools menu)."
Well, although I can see and manually insert autotexts from the attached
and the loaded global templates, I can't insert them by name from a macro if
they are in the global template. This puts a serious dent in our plan to
use global templates as storage for autotexts ... any solutions?
 
T

Tsu Dho Nimh

JGM said:
Hi Tsu Dho,

I think you are confusing two different things.
First of all, I have to make an assumption because you were not very clear
on what you are trying to achieve. I assume that you are trying to insert in
an AUTOTEXT entry at the cursor in the active document.

Yes ... had the help file open at the wrong spot. I can see the
AutoText entries and manually insert them, but VBA doesn't seem
to be able to access them without all sorts of work-arounds, like
temporarily attaching the DOC to the template with the autotexts
you want, then replacing the oroiginal template.

Oddly, macros can be called programmatically from any global
template.
Selection.Collapse Direction:=wdCollapseEnd
NormalTemplate.AutoTextEntries("TheWorld").Insert _
Where:=Selection.Range, RichText:=True

Exactly ... but if the AutoText is in an active "global"
template" nothing happens.
or, if you have a template that contains the Autotext (not necessarily the
one used to create the current document), you may want to play around with
something like:

Templates("D:\MyPath\MyGlobalTemplate.dot").AutoTextEntries("Test").Insert _
Where:=Selection.Range, RichText:=True

That will work, but is not nearly as convenient as going straight
to the global template. Big legal firm, lots of templates and
lots fo autotexts.



Tsu Dho Nimh
 
W

Word Heretic

G'day Tsu Dho Nimh <[email protected]>,

Global templates are available via the templates collection. One of
them has name that matches the required global template. You use that
template offset, Templates(n). , and go straight for the autotext
entries:

templates(1).AutoTextEntries




Tsu Dho Nimh said:
Care to be a bit less cryptic?



Tsu Dho Nimh

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
wordheretic.com

Replies offlist may require payment.
 

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