AutoText - controlling from Excel VBA

S

sam

Hi - hope someone can help:

I am using Excel 2003 as a "front end" (at manager's request, as I would
prefer to use a Word userform). The intention is for the user to select
various options in Excel which then creates and populates a Word document.

The Word document is a template - I have managed to create a new document,
based on the template and populate at the required bookmarks, however my
problem is when I want to insert Autotext - it just doesn't appear.

I have successful inserted AutoText when just using Word VBA, so I think the
problem is the way I am accessing it from Excel - I have a variable (oDoc) to
mean the active document and the code:

oDoc.AttachedTemplate.AutoTextEntries("vvvf").Insert

Can anyone help me - it's driving me crazy!

Thanks
sam
 
J

Jay Freedman

Hi Sam,

You're on the right track. But the insert method takes one required
argument and may take a second optional argument. The syntax should be

oDoc.AttachedTemplate.AutoTextEntries("vvvf").Insert _
Where:=someRange

or

oDoc.AttachedTemplate.AutoTextEntries("vvvf").Insert _
Where:=someRange, RichText:=True

where someRange is a Range object that's the place in the document to
insert the entry. If you don't have that in your code, you should be
seeing a compile error. If you do have it but just omitted it from
your post, try single-stepping through the code (F8) and looking at
the definition of the range just before the .Insert executes.

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

sam

Hi Jay - that's it

I needed

Where:=oWord.Selection.Range, RichText:=True

You don't know how :) I now am - I've been working on this all day!

Thank you very much

sam
 

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