AutoText entry not in Normal.dot

L

Luc Benninger

I have a global template (myDot.dot) with following VBA code in it to
create a new AutoText entry. This new entry should not be saved in the
Normal.dot but in the myDot.dot:

CustomizationContext = ThisDocument
Selection.CreateAutoTextEntry "AT_Label", "AT_Category"

But it seems that the CustomizationContext instruction has no influence!
The entry is still saved in Normal.dot.

Any hints?
Thanks a lot, Luc
 
J

Jay Freedman

Luc said:
I have a global template (myDot.dot) with following VBA code in it to
create a new AutoText entry. This new entry should not be saved in the
Normal.dot but in the myDot.dot:

CustomizationContext = ThisDocument
Selection.CreateAutoTextEntry "AT_Label", "AT_Category"

But it seems that the CustomizationContext instruction has no
influence! The entry is still saved in Normal.dot.

Any hints?
Thanks a lot, Luc

Hi Luc,

"ThisDocument" is the wrong place to point to. Instead, use
CustomizationContext = ActiveDocument.AttachedTemplate

See http://word.mvps.org/faqs/macrosvba/AddMenu.htm for an example.
 
C

Charles Kenyon

Hi Luc and Jay,

Jay, your code works when it is in the attached template and that is where
you
want to store the AutoText entry.

The following (a combination of the two) works for storing in a global
template instead:

Sub ATTry()
CustomizationContext = ThisDocument.AttachedTemplate
Selection.CreateAutoTextEntry "AT_Label", "AT_Category"
End Sub

ThisDocument, by itself, doesn't work because it doesn't describe a template
(which is the only object that can hold AutoText), I think.
IMHO ActiveDocument.AttachedTemplate should never describe a global
template, other than normal.dot.

Note, I don't know how long the CustomizationContext sticks. I expect at
least as long as the procedure is running but suspect that it may be as long
as the global is loaded after the procedure is run. You should test this and
make sure because otherwise you are likely to end up with stray
customizations in your global.

Also, you probably want to save your global at the end of the procedure.

ThisDocument.Save
 
L

Luc Benninger

Thank you very much for your replies. Unfortunately none of your
suggestions seem to work for me. The new AT-entry is still saved in
Normal.dot. Does it really work that way at your end? I'm using Word XP.
Thanks again
Luc
 
C

Charles Kenyon

Sorry, I should have tested before posting. It still goes into normal.dot
even if the attached template is not normal.dot. This tells me that the
customization context is irrelevant for purposes of storing AT entries. The
codeI wrote puts the customization context in the global template, but
doesn't change where AT entries are stored.

The AutoTextEntries.Add method lets you specify the template (actually seems
to require it) but doesn't let you specify the style. It uses the style of
the selection for the category.

You may have to actually have and use styles and the AutoTextEntries.Add
method to do what you want. Jay has a template "AutoTextLoader.dot" with
code for loading ATEntries into a template from a table. You may want to
look at it and see if it will help you do what you need. You can get it from
my site at http://addbalance.com/word/download.htm#Templates.
 

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