AutoText in Word 2007

G

George

Hi

In Word 2003 I had a couple of dot-moduls
I have used them as program- and/or AutoText-
containers. So I was able to f.e. insert a AutoText-
entry from one dot-AddIn into a document
which has based on another .dot-template.

In Word 2007 I have now the problem, that
I am only able to insert AutoText-entries from
the Template a document is based on.

X* = Template incl. path
Y* = Name of AT

When I use the line
Application.Templates(X*).AutoTextEntries(Y*).Insert Where:=Selection.range,
RichText:=True
I get runtime error 5941, saying the AT is not
available.

When I try it manually, it works.

When I do it manually and record a macro,
the following code gets recorded:
ActiveDocument.AttachedTemplate.BuildingBlockEntries(Y*).Insert
Where:=Selection.range, RichText:=True

When I start the recorded macro, I again get the runtime error 5941 ...

Does somebody has me a hint? Thanks for any help.

George
 
P

Pesach Shelnitz

Hi George,

In Word 2007, the AutoText feature from previous versions has become part of
the Building Blocks feature, which includes numerous galleries of building
blocks, one of which is called Quick Parts. There is also an AutoText
gallery.

In Word 2007, you can create AutoText entries manually by selecting the text
that you want to be saved as a Quick Part or AutoText entry and press Alt+F3,
just as you did in Word 2003 for AutoText entries. In the dialog box that
opens, notice that the Gallery is set to Quick Parts by default. You can
change Quick Parts to AutoText in the Gallery dropdown list. This change is
not necessary, and if you do make this change, your entry will not be
displayed in the list of Quick Parts that you can display by clicking Quick
Parts in the Text group of the Insert tab on the Ribbon. In this dialog box,
you can change the location where the Quick Part or AutoText entry is saved
from the default Building Blocks template to the active template.

Building blocks that are saved in the default Building Blocks template are
accessed through the Templates(1).BuildingBlockEntries property. The
following code inserts a building block called MyQuickPart at the insertion
point.

Templates(1).BuildingBlockEntries("MyQuickPart").Insert _
Where:=Selection.Range, _
RichText:=True

Either of the following code snippets inserts a building block called
MyAutotext that was saved in the Normal template at the insertion point.

NormalTemplate.BuildingBlockEntries("MyAutotext").Insert Where:= _
Selection.Range, RichText:=True
Or
ActiveDocument.AttachedTemplate.AutoTextEntries("MyAutotext").Insert _
Where:= Selection.Range, RichText:=True
 
T

Tony Jollans

Building blocks that are saved in the default Building Blocks template are
accessed through the Templates(1).BuildingBlockEntries property. The
following code inserts a building block called MyQuickPart at the
insertion
point.

Templates(1).BuildingBlockEntries("MyQuickPart").Insert _
Where:=Selection.Range, _
RichText:=True

Only if "Building Blocks.dotx" is the first template in your Templates
collection, something over which you, arguably, have an element of control,
but something which is certainly not guaranteed.
Either of the following code snippets inserts a building block called
MyAutotext that was saved in the Normal template at the insertion point.

NormalTemplate.BuildingBlockEntries("MyAutotext").Insert Where:= _
Selection.Range, RichText:=True
Or
ActiveDocument.AttachedTemplate.AutoTextEntries("MyAutotext").Insert _
Where:= Selection.Range, RichText:=True

The second example only looks in normal.dotm if your document is based on
normal.dotm
 
A

Adri

I would check to ensure that the autotext entry is in fact in the "attached
document", and not in the Building Blocks.dotx (which is the default location
for saving autotext now). Because when I record a macro to insert an
autotext that I know is stored only in Building Blocks.dotx, it records:

ActiveDocument.AttachedTemplate.BuildingBlockEntries("Test autotext"). _
Insert Where:=Selection.Range, RichText:=True

I don't know why it would record that way, but that's what I got.

When I have autotext correctly stored in the attached template, I use the
above code all the time to insert autotext in the resulting document. So I
suspect your autotext may be in the Building Blocks.dotx, and not in the
attached template.

Adri
 
A

Adri

Sorry, I just read your original post over again and realized you're asking
how to insert autotext from another template entirely, i.e. not the attached
template and not the Building Blocks.dotx.

I use the following code to insert autotext from a startup template, at a
bookmark location in the current doc...

I first set strStartupTemplate to whatever my startup template location/name
is, for example:

strStartupTemplate = Application.StartupPath + "\MyStartup.dotm"

and then:


Templates(strStartupTemplate).BuildingBlockEntries("TestAutotext"). _
Insert Where:=ActiveDocument.Bookmarks("TestBookmark").Range,
RichText:=True

Hope this helps.

Adri
 
G

George

Dear Adri, Tony and Pesach

Many thanks for your support and your
help. I was not able to get it work in the
way I had it under Word 2003 (gathering
an AutoText-Entry from another template).

I helped myself by using a workaround: I
copied the AutoText-Entries in the two
templates directly.

Again, many thanks for your support!

Best Regards
 

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