Autotext code not working all of a sudden!

M

Mark

I have autotext stored in aglobal template which I callupon from code stored
in that global template and place it in the current document:

Selection.EndKey Unit:=wdStory ' goto end of document
ThisDocument.AttachedTemplate.AutoTextEntries(sMG12).Insert Where _
:=Selection.Range, RichText:=True 'Insert autotext entry

For some strange reason, this has stopped working, can anyone assist me with
a solution, please?
 
C

Charles Kenyon

ThisDocument is the document which holds your code, probably a template.
Unless it is the same template that holds your AutoText your code isn't
likely to work. The attached template for a template is the template itself
as far as I have been able to tell.

When you say it has stopped working, what has stopped? Does it go to the end
of your document? Does it give you an error message?

If the name of the AutoTextEntry is MG12 I would include it in quotation
marks.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
M

Mark

Charles,

When I record a macro I can insert the autotext from the global template
which is not the NormalTemplate. Despite the autotext not being in the
NormalTemplate the code recorded is:

Application.DisplayAutoCompleteTips = True
NormalTemplate.AutoTextEntries(MG12).Insert Where:= _
Selection.Range, RichText:=True

Yet when I put this code into a module and run it I get the following message:

Runtime error 5941

The requested memebr of the collection does not exist !!!!


Mark
 
M

Mark

Hi Charles,

The autotext is held in this template.

The MG12 is a defined string with loads of variations so the code in the
document that calls the code in the template with the autotext sets the
string first.

The error code I am now getting is: Run time error 32809 Application-defined
or object defined error.

Mark
 
C

Charles Kenyon

See if you can track down Jay Freedman's AutoText loader. The code in it may
help you.
I worked on this a couple of years ago and found a solution but I don't
remember what it was, just that it wasn't easy to figure out/ find. This is
one of the situations where recorded macros just don't work.

If you haven't found the AutoText loader by this weekend, write back and
I'll find a link for you. No time right now.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
J

Jay Freedman

Actually, the code you want to look at is in the AutoTextDumper
template, the other half of the pair. They can both be downloaded from
http://jay-freedman.info.

I'm not sure this is going to help, though. AutoTextDumper cheats a
bit by creating a new document based on the template that contains the
autotext entries, and then calls

For Each ATentry In oDestDoc.AttachedTemplate.AutoTextEntries
...
ATentry.Insert Where:=rgAT, RichText:=True

to do the insertions. It doesn't look like that technique is directly
applicable to what you're doing.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
M

Mark

So why would my code work at one time then suddenly stop and debug?

Ok then, the situation I have got is, I have a word document. It has to be
a word DOCUMENT, not TEMPLATE for a program (which cannot be changed!) that
it links to. These documents have fields in them which are populated from
the program. For example {FORMTEXT gperson1_fullname} . On some occasions
extra pages of the document are required so the fields in the extra pages are
incremented {FORMTEXT gperson2_fullname} etc. I need a repository for these
extra pages and of course autotext cannot be stored in a document, so it has
to be a template. The normal template is not the place for these pages to be
stored as we have experienced difficulties in the past with storing things in
the normal template.

Any suggestions/solutions would be greatly appreciated.
 
C

Charles Kenyon

You might try using a template rather than a document with your other
program. See if you can fool your program by changing the filename extension
(in Windows, not Word) from .dot to .doc.

Note, this is not generally a good idea because it leads to confusion.
However, Word will still know that it is dealing with a template.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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